Summary
Memorize keywords, tips and code snippets for http://www.ruby-lang.org/en/, the scripting language.
Basics
| Question | Answer (memorize) |
| print a string | puts "hi" |
| run a ruby script (from the command-line) | ruby hi.ruby |
| string with variable | "hi #{s}" |
| string with expression | "hi #{1 + 2}" |
| multi-line string | "foo bar" |
Functions and Structures
| Question (memorize) | Answer (memorize) |
| Ruby term for "Map" (or Associative Array) | Hash |
| if block | if(i == 5) puts "five" end |
| define a function | def hi(a) puts a end |
| invoke a function | hi("you") |
| define a class | class Hi # Functions end |
| instantiate a class | h = Hi.new() |
Lists
| Question | Answer (memorize) |
| create a list | l = ["foo", "bar"] |
| append to list | l << "third" |
| iterate through list | l.each{ |i| puts i } |
| join a list (into one string) | l.join( "," ) |
| access 2nd element (in a list) | l[1] |
| shorthand for [3, 4, 5] | 3..5 |
| double list | l * 2 |
Classes and Objects
| Question (memorize) | Answer (memorize) |
| Create a class | <pre>class Hello def salute puts "Hello!" end end
|
Frameworks
| Framework (memorize) | Description (memorize) |
| gems | ruby packages |
| build tool | Rake |
| web app framework | Ruby on Rails |
| lightweight webapp framework | Camping |
| RMagick | manipulate images (wraps ImageMagick) |
Ruby on Rails
Rails is the most popular framework for creating webapps with ruby.
| Question (memorize) | Answer (memorize) |
| principles | - don't repeat yourself - convention over configuration |
| scaffolding | skeleton code frameworks |
| database framework | ActiveRecord |
| Locomotive | Rails installer (for OS X) |
| templates | .rhtml files (via ERb - Embedded Ruby) |
Pages
See also
http://ruby.codehaus.org/Quick+Start"
|
|