[ next ] [ prev ] [ contents ] [ up to The Top Ten Reasons I Like Ruby ] Invitation To Ruby

Reason 5 -- Ruby is Interactive!

IRB -- Interactive Ruby

traken$ irb
irb(main):001:0> def fact(n)
irb(main):002:1>   return 1 if n == 0
irb(main):003:1>   n * fact(n-1)
irb(main):004:1> end
nil
irb(main):005:0> fact(5)
120
irb(main):006:0> fact(50)
30414093201713378043612608166064768844377641568960512000000000000
irb(main):007:0> Integer.superclass
Numeric
irb(main):008:0> 10.methods
["next", "id2name", "times", "size", "-", "zero?", "|", "/", "-@", "step", 
"to_f", "**", "modulo", "%", "upto", "&", "~", "<", "<=>", "succ", "[]", "^",
"==", "type", "downto", ">", "divmod", "<<", ">>", ">=", "abs", "*", "to_s",
"<=", "+", "round", "to_int", "to_i", "ceil", "integer?", "floor", "chr", 
"truncate", "prec_f", "prec_i", "prec", "nonzero?", "clone", "remainder", "+@", 
"eql?", "===", "coerce", "between?", "dup", "protected_methods", "frozen?", 
"respond_to?", "class", "kind_of?", "__send__", "nil?", "instance_eval", 
"public_methods", "untaint", "__id__", "display", "inspect", "taint", "hash", 
"=~", "private_methods", "to_a", "is_a?", "equal?", "singleton_methods", "freeze", 
"instance_of?", "send", "methods", "method", "tainted?", "instance_variables", 
"id", "extend"]


[ next ] [ prev ] [ contents ] [ up to The Top Ten Reasons I Like Ruby ] Copyright 2002 by Jim Weirich.
All rights reserved.