CSE341 $ irb >> 1 => 1 >> "hello" => "hello" >> puts "hello" hello => nil >> 1+2 => 3 >> 1.class => Fixnum >> 1.methods => ["%", "odd?", "inspect", "prec_i", "<<", "tap", "div", "&", "denominator", "clone", ">>", "public_methods", "object_id", "__send__", "instance_variable_defined?", "gcdlcm", "equal?", "freeze", "to_sym", "*", "ord", "+", "extend", "next", "send", "round", "gcd", "methods", "prec_f", "-", "even?", "taguri", "singleton_method_added", "divmod", "hash", "/", "integer?", "downto", "dup", "to_enum", "taguri=", "instance_variables", "to_r", "|", "eql?", "rdiv", "size", "id", "instance_eval", "truncate", "~", "to_i", "singleton_methods", "to_yaml_style", "modulo", "taint", "zero?", "times", "numerator", "instance_variable_get", "frozen?", "enum_for", "display", "instance_of?", "^", "method", "to_a", "rpower", "+@", "-@", "quo", "instance_exec", "type", "**", "upto", "to_f", "<", "step", "protected_methods", "<=>", "between?", "==", "remainder", ">", "===", "to_int", "nonzero?", "pred", "instance_variable_set", "coerce", "to_yaml", "respond_to?", "kind_of?", "floor", "succ", ">=", "prec", "to_yaml_properties", "to_s", "<=", "fdiv", "class", "private_methods", "=~", "tainted?", "__id__", "abs", "untaint", "nil?", "chr", "lcm", "id2name", "power!", "is_a?", "ceil", "[]"] >> 1.methods.class => Array >> 1.methods.length => 116 >> 1.+(2) => 3 >> (1.+(2)).class => Fixnum >> 3.14.class => Float >> "hello".class => String >> "hello".methods => ["upcase!", "zip", "find_index", "between?", "unpack", "enum_slice", "to_f", "minmax", "lines", "sub", "methods", "send", "replace", "empty?", "group_by", "squeeze", "crypt", "gsub!", "taint", "instance_variable_defined?", "match", "downcase!", "take", "find_all", "min_by", "bytes", "each_cons", "entries", "gsub", "singleton_methods", "instance_eval", "is_complex_yaml?", "to_str", "first", "chop!", "intern", "nil?", "succ", "capitalize!", "take_while", "select", "max_by", "chars", "enum_cons", "tr!", "protected_methods", "instance_exec", "display", "sort", "chop", "tainted?", "is_binary_data?", "dump", "method", "include?", "untaint", "instance_of?", "chomp!", "swapcase!", "drop", "equal?", "reject", "hex", "minmax_by", "sum", "hash", "private_methods", "all?", "tr_s!", "sort_by", "chomp", "upcase", "start_with?", "succ!", "kind_of?", "to_yaml", "strip!", "freeze", "drop_while", "eql?", "next", "collect", "oct", "id", "slice", "casecmp", "grep", "strip", "any?", "delete!", "public_methods", "to_yaml_properties", "end_with?", "downcase", "%", "object_id", "is_a?", "scan", "lstrip!", "cycle", "map", "member?", "tap", "type", "*", "split", "insert", "each_with_index", "+", "count", "lstrip", "one?", "squeeze!", "instance_variables", "__id__", "frozen?", "capitalize", "next!", "each_line", "to_enum", "rstrip!", "to_a", "ljust", "respond_to?", "upto", "taguri", "each", "inject", "tr", "slice!", "class", "reverse", "length", "enum_with_index", "rpartition", "taguri=", "rstrip", "<=>", "none?", "instance_variable_get", "find", "==", "swapcase", "__send__", "===", "min", "each_byte", "enum_for", "extend", "to_s", "rjust", "index", ">=", "to_yaml_style", "size", "reduce", "tr_s", "<=", "clone", "reverse_each", "to_sym", "bytesize", "instance_variable_set", "=~", "<", "detect", "max", "each_char", "each_slice", ">", "to_i", "center", "inspect", "[]", "reverse!", "rindex", "partition", "delete", "[]=", "concat", "sub!", "dup", "<<"] >> "hello".reverse => "olleh" >> s = "hi " + "there" => "hi there" >> s => "hi there" >> a = [ 1,2,3 ] => [1, 2, 3] >> a.class => Array >> a[2] => 3 >> a[1]=17 => 17 >> a.length => 3 >> a => [1, 17, 3] >> a[10] = 42 => 42 >> a => [1, 17, 3, nil, nil, nil, nil, nil, nil, nil, 42] >> a[-8] => nil >> a[-9] => 3 >> a[-12] => nil >> nil => nil >> nil.class => NilClass >> nil.methods => ["inspect", "tap", "&", "clone", "public_methods", "object_id", "__send__", "instance_variable_defined?", "equal?", "freeze", "extend", "send", "methods", "taguri", "hash", "dup", "to_enum", "taguri=", "instance_variables", "|", "eql?", "instance_eval", "id", "to_i", "to_yaml_style", "singleton_methods", "taint", "frozen?", "instance_variable_get", "enum_for", "^", "instance_of?", "display", "to_a", "method", "type", "to_f", "instance_exec", "protected_methods", "==", "===", "instance_variable_set", "to_yaml", "kind_of?", "respond_to?", "to_yaml_properties", "to_s", "class", "private_methods", "=~", "tainted?", "__id__", "untaint", "nil?", "is_a?"] >> 1.class => Fixnum >> Fixnum.class => Class >> Class.methods => ["private_class_method", "inspect", "name", "yaml_tag_subclasses?", "tap", "clone", "public_methods", "object_id", "__send__", "method_defined?", "instance_variable_defined?", "equal?", "freeze", "extend", "send", "const_defined?", "methods", "ancestors", "module_eval", "instance_method", "taguri", "hash", "autoload?", "yaml_as", "dup", "to_enum", "instance_methods", "public_method_defined?", "taguri=", "instance_variables", "class_variable_defined?", "eql?", "constants", "id", "instance_eval", "singleton_methods", "module_exec", "to_yaml_style", "const_missing", "taint", "instance_variable_get", "frozen?", "enum_for", "private_method_defined?", "public_instance_methods", "display", "instance_of?", "superclass", "method", "to_a", "included_modules", "const_get", "instance_exec", "type", "<", "protected_methods", "<=>", "yaml_tag_read_class", "class_eval", "==", "class_variables", ">", "===", "yaml_tag_class_name", "instance_variable_set", "protected_instance_methods", "protected_method_defined?", "to_yaml", "respond_to?", "kind_of?", ">=", "public_class_method", "to_yaml_properties", "to_s", "<=", "const_set", "allocate", "class", "new", "private_methods", "=~", "tainted?", "__id__", "class_exec", "autoload", "untaint", "nil?", "private_instance_methods", "nesting", "include?", "is_a?"] >> Class.class => Class >> n = { "the" => 35, "xyzzy" => 1 } => {"xyzzy"=>1, "the"=>35} >> n["the"] => 35 >> n["nogots"] = 5 => 5 >> n => {"nogots"=>5, "xyzzy"=>1, "the"=>35} >> if 1 > 0 >> puts "works" >> else ?> puts "broken" >> end works => nil >> def say(something) >> puts something >> end => nil >> say "hello" hello => nil >> class Toy >> def initialize(name,color) >> @name = name >> @color = color >> end >> def name >> @name >> end >> end => nil >> Toy.methods => ["private_class_method", "inspect", "name", "yaml_tag_subclasses?", "tap", "clone", "public_methods", "object_id", "__send__", "method_defined?", "instance_variable_defined?", "equal?", "freeze", "extend", "send", "const_defined?", "methods", "ancestors", "module_eval", "instance_method", "taguri", "hash", "autoload?", "yaml_as", "dup", "to_enum", "instance_methods", "public_method_defined?", "taguri=", "instance_variables", "class_variable_defined?", "eql?", "constants", "id", "instance_eval", "singleton_methods", "module_exec", "to_yaml_style", "const_missing", "taint", "instance_variable_get", "frozen?", "enum_for", "private_method_defined?", "public_instance_methods", "display", "instance_of?", "superclass", "method", "to_a", "included_modules", "const_get", "instance_exec", "type", "<", "protected_methods", "<=>", "yaml_tag_read_class", "class_eval", "==", "class_variables", ">", "===", "yaml_tag_class_name", "instance_variable_set", "protected_instance_methods", "protected_method_defined?", "to_yaml", "respond_to?", "kind_of?", ">=", "public_class_method", "to_yaml_properties", "to_s", "<=", "const_set", "allocate", "class", "new", "private_methods", "=~", "tainted?", "__id__", "class_exec", "autoload", "untaint", "nil?", "private_instance_methods", "say", "include?", "is_a?"] >> truck = Toy.new("firetruck","red") => # >> truck => # >> truck.name => "firetruck" >> truck.color NoMethodError: undefined method `color' for # from (irb):62 >> class Toy >> def color >> @color >> end >> end => nil >> truck.color => "red" >> truck.color = "green" NoMethodError: undefined method `color=' for # from (irb):69 >> class Toy >> def color= >> end >> def color=(color) >> @color = color >> end >> end => nil >> truck.color => "red" >> truck.color = "ruby" => "ruby" >> truck => # >> 1.class => Fixnum >> class Fixnum >> def +(other) >> 17 >> end >> end => nil >> 1+1 => 17 >> ^D CSE341$ irb >> names = [ "harpo", "groucho", "chico" ] => ["harpo", "groucho", "chico"] >> names[3] = "zeppo" => "zeppo" >> names => ["harpo", "groucho", "chico", "zeppo"] >> names.each { puts "this works" } this works this works this works this works => ["harpo", "groucho", "chico", "zeppo"] >> names.each { | w | puts w } harpo groucho chico zeppo => ["harpo", "groucho", "chico", "zeppo"] >> 10.times { puts "it works!" } it works! it works! it works! it works! it works! it works! it works! it works! it works! it works! => 10 >> ^D