Fall 2012 -- Ruby 1.9
--Short introduction to Ruby:
References:

Getting started:
Interactive scripts:

Some important language features:
  1. Multi-paradigm language
    1. concurrent and object-oriented (class-based) are all supported
  2. dynamically typed 
    1. -- no declaration of variables
    2. -- type "lives" with objects, not names
  3. reference model - like smalltalk
  4. line breaks are significant and taken as the end of a statement; a semicolon may be equivalently used
  5. "end" terminates all blocks
  6. indentation is not significant
  7. "#" begins a comment until the end of line
  8. && -- logical  and operator,   != logical Not equal operator
  9. elsif can be used for "optional parts"
  10. if n < 5 then
        return 10
    elsif n < 20 then
        return 100
    else
        return 1000

Example code:
fib.rb

# Recursive definition of  the nth fibonacci number
module FibEx

    def fib (n)
      if (n < 2) then
        return 1
      else 
        return fib(n-1) + fib(n-2)
      end #End of "if/else"
    end #End of "function/method"
 
    def fibi (n)
        a = 1
        b = 1
        s = 1
       while (s < n)
         s += 1
         t = a + b
         a = b
         b = t
       end #End while
       return b
    end #End of fibi

  
    def fibf (n)
       a = 1
       b = 1
       for i in 2 .. n    # i assumes the values 2 to n
          t = a + b
          a = b
          b = t
        end #End of for
        return b
    end #End of fibf

    def fibl(n)
      a, b = 0, 1
      n.times do  #Even numbers are objects
        a, b = b, a+b
      end
      return a
      end  
     

end #End of Module

# To use methods in IRB we need to include this module

include FibEx
# prints out the results after running in SciTE with "GO" or after loading in irb or running the script in Ruby shell.
puts fib(8)
puts fibf(8)
puts fibl(8)