11
URails Meeting 002

URails

  • Upload
    kalil

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

URails. Meeting 002. Goals. Learn some Linux Running Linux from the command-line Finding help for the command-line Filesystem Installing from source (RVM) Learn some Ruby Go over basic syntax How to execute a Ruby file Practice!. Install Cygwin. Go to www.cygwin.com - PowerPoint PPT Presentation

Citation preview

Page 1: URails

URails

Meeting 002

Page 2: URails

Goals

• Learn some Linux– Running Linux from the command-line– Finding help for the command-line– Filesystem– Installing from source (RVM)

• Learn some Ruby– Go over basic syntax– How to execute a Ruby file– Practice!

Page 3: URails

Install Cygwin

• Go to www.cygwin.com• Download setup.exe• Install the following packages:– git, svn, ncurses, openssl, make, g++, gcc, readline,

xorg-server, xinit

Page 4: URails

Linux Commands

• Basic Format:– <program> <parameters> -<options>– Analogous to writing a method

• Examples– ls lists the files in a directory

• ls –l lists the files vertically and shows permissions

– cd <some_directory> “moves” you to a different directory• cd ../ moves you back a directory

• Time to practice!

Page 5: URails

Help For Linux Commands

• How can you know what parameters a program takes?– Most programs have a --help option• gcc --help (gcc is a C compiler)

– Most programs have a man page (man for manual)• man ls

Page 6: URails

Linux Filesystem

• Essentially two parts:• System Files• User Files

SystemUser

Page 7: URails

Linux Filesystem (cont.)

• / = root (system files)• ~ = user/home (user files)– ~/ is short for /home/<user_name>– If your username was joe, typing cd ~/ would take you

to /home/joe/• This division is nice because all files that need to be

backed up are typically in your user folder.• User folder is similar to the My Documents folder on

Windows• Practice with RVM!

Page 8: URails

Install RVM (Ruby Version Manager)

• Cygwin users: Talk to me after, find a friend• Go to RVM website (see URails website)• Why use RVM?– Ruby (and Rails) is fast-changing– Let’s say you build an Rails app using Rails 3.0 and Ruby

1.8.7. Rails 3.1 comes out! Ruby 1.9.2 comes out! You install them, start using all their features, then come back to your Rails 3.0 project. They aren’t compatible. What do you do?

– Use RVM! It manages different versions of Ruby and Gems

Page 9: URails

Text Editor and IDE’s• What IDE to use for Ruby/Rails?

– If you’re hardcore (Not IDE’s, just Text Editors)• vi (also called vim) (steep learning curve, worth it)• emacs (slightly steep learning curve, probably worth it)

– Less hardcore• nano (simple linux text editor, smaller learning curve but less features)• gedit (nice middle ground of simple text editing and some advanced features)• NotePad/WordPad (No text highlighting)

– Something more like Eclipse• Eclipse works, takes some setting up, never done it• RubyMine, probably good but costs money

– My recommendation:• Don’t use a fancy IDE, it’s very worth it to get practice in an environment without auto-

complete/auto-compilation warnings, etc. Rails is not an environment where there’s a lot to gain using an IDE.

– Feel free to google “Rails IDE” for other options, I’ve only used vi

Page 10: URails

Scripting vs Programming• What’s the difference?– Not a lot (in my opinion)– Scripting languages can be considered

“lightweight” programming languages– Usually interpreted, not compiled– Usually looser syntax requirements– “Details” taken care of for you• Garbage Collection (Java has this too)• Dynamic Typing (no need to declare variable types)

– Programming: int x = 5;– Scripting: x = 5

Page 11: URails

Practice• Create a class called Fraction with the following methods:

– Constructor that takes two numbers– Accessors and mutators for numerator and denominator (as well as instance

variables)– to_s method (toString)– to_f method (toFloat)– simplify (optional)

• Create a script that does the following– Creates an array– Stores 3 Fraction objects in the array– Permutes the objects in the array in a random order (there’s a single method for

this, look at the Array documentation!)– Create a Hash with the same Fractions where the key is the fraction in english (i.e.

if the fraction is 1/5, the symbol would be :one_fifth)– Print the contents of the Array to the console