Ruby Overview
  • scripting language (dynamic, unstructured)
  • meta programming (can call itself and write itself) 
  • pure OO (object oriented, everything's an object)
  • large language - gazillion features 
  • Kind of slow - not your best choice to run programs fast 
Syntax
  • Don't need to declare variables
  • New line is a statement operator (defines a new line is starting/ending) - but not always (ex. paranthesis)  
Variables
  • Dynamically typed. Values have type, not the variables. 
  • Globals - $variableName
  • Instance var in object - @foo
  • Class variable - @@foo
  • "Constant" - MAX_FOO 
Strings
Single and double quotes work as strings. 
%q vs %Q (basically you pick your own delimiter and the string is like single/double quotes) 
Here documents (lots of HTML)
Overview
Data Types
Symbols
More efficient than strings (used for like fixed names) 
Data Structures
Arrays and Hashes created by Array.new/Hash.new
For Statements
for value in array do
 . . .
end 
Methods 
Example:
def fac(x)
   if x <= 1 then 
      return 1
   end
   return x * fac (x-1)
end 

Something is ALWAYS RETURNED.  Last statement is return value (or NIL if it's BS) 
- Every method has a class
- Optional parans (puts "Hello World") - if there is space after function name, then assumes no parans there 
Keyword Arguments
Can have a dynamic number of args per method visa a hash object.  Can remove the {}'s and just pass in the key-value pairs as args. 
   Login to remove ads X
Feedback | How-To