Script started on Fri Nov 4 13:29:40 2016 bash-3.2$ irb irb(main):001:0> load "silly.rb" Hello, World! => true irb(main):002:0> 42.class => Fixnum irb(main):003:0> -42.abs => 42 irb(main):004:0> 42.methods => [:to_s, :inspect, :-@, :+, :-, :*, :/, :div, :%, :modulo, :divmod, :fdiv, :**, :abs, :magnitude, :==, :===, :<=>, :>, :>=, :<, :<=, :~, :&, :|, :^, :[], :<<, :>>, :to_f, :size, :zero?, :odd?, :even?, :succ, :double, :integer?, :upto, :downto, :times, :next, :pred, :chr, :ord, :to_i, :to_int, :floor, :ceil, :truncate, :round, :gcd, :lcm, :gcdlcm, :numerator, :denominator, :to_r, :rationalize, :singleton_method_added, :coerce, :i, :+@, :eql?, :quo, :remainder, :real?, :nonzero?, :step, :to_c, :real, :imaginary, :imag, :abs2, :arg, :angle, :phase, :rectangular, :rect, :polar, :conjugate, :conj, :between?, :m, :nil?, :=~, :!~, :hash, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__] irb(main):005:0> athing = A.new => # irb(main):006:0> athing.m1 => 34 irb(main):007:0> athing.m2(1, 2) => 15 irb(main):008:0> athing.m2(2,1) => false irb(main):009:0> athing.m3(17) NoMethodError: undefined method `m3' for # from (irb):9 from /usr/bin/irb:12:in `
' irb(main):010:0> class A irb(main):011:1> def m3(x) irb(main):012:2> "we have a m3 method now!" irb(main):013:2> end irb(main):014:1> end => nil irb(main):015:0> athing.m3(17) => "we have a m3 method now!" irb(main):016:0> cthing = c.new NameError: undefined local variable or method `c' for main:Object from (irb):16 from /usr/bin/irb:12:in `
' irb(main):017:0> cthing = C.new => # irb(main):018:0> cthing.class => C irb(main):019:0> cthing.m1 hi => # irb(main):020:0> cthing.m1.m2.m3 hi bye => # irb(main):021:0> athing.m1.m2(1,2) NoMethodError: undefined method `m2' for 34:Fixnum from (irb):21 from /usr/bin/irb:12:in `
' irb(main):022:0> load "Rat.rb" => true irb(main):023:0> half = Rat.new(4,8) => # irb(main):024:0> half => # irb(main):025:0> puts half 1/2 => nil irb(main):026:0> "hello" => "hello" irb(main):027:0> puts "hello" hello => nil irb(main):028:0> two = Rat.new(2) => # irb(main):029:0> puts two 2 => nil irb(main):030:0> half+two => # irb(main):031:0> half+2 NoMethodError: undefined method `num' for 2:Fixnum from Rat.rb:43:in `add!' from Rat.rb:57:in `+' from (irb):31 from /usr/bin/irb:12:in `
' irb(main):032:0> half*two NoMethodError: undefined method `*' for # from (irb):32 from /usr/bin/irb:12:in `
' irb(main):033:0> half+two => # irb(main):034:0> half.+(two) => # irb(main):035:0> nums = [1, 2, 3, 4, 5] => [1, 2, 3, 4, 5] irb(main):036:0> nums => [1, 2, 3, 4, 5] irb(main):037:0> nums[2] => 3 irb(main):038:0> nums[-1] => 5 irb(main):039:0> nums[1,3] => [2, 3, 4] irb(main):040:0> nums[4]=17 => 17 irb(main):041:0> nums => [1, 2, 3, 4, 17] irb(main):042:0> nums[8]=-8 => -8 irb(main):043:0> nums => [1, 2, 3, 4, 17, nil, nil, nil, -8] irb(main):044:0> nums.class => Array irb(main):045:0> nums.methods => [:inspect, :to_s, :to_a, :to_ary, :frozen?, :==, :eql?, :hash, :[], :[]=, :at, :fetch, :first, :last, :concat, :<<, :push, :pop, :shift, :unshift, :insert, :each, :each_index, :reverse_each, :length, :size, :empty?, :find_index, :index, :rindex, :join, :reverse, :reverse!, :rotate, :rotate!, :sort, :sort!, :sort_by!, :collect, :collect!, :map, :map!, :select, :select!, :keep_if, :values_at, :delete, :delete_at, :delete_if, :reject, :reject!, :zip, :transpose, :replace, :clear, :fill, :include?, :<=>, :slice, :slice!, :assoc, :rassoc, :+, :*, :-, :&, :|, :uniq, :uniq!, :compact, :compact!, :flatten, :flatten!, :count, :shuffle!, :shuffle, :sample, :cycle, :permutation, :combination, :repeated_permutation, :repeated_combination, :product, :take, :take_while, :drop, :drop_while, :bsearch, :pack, :entries, :sort_by, :grep, :find, :detect, :find_all, :flat_map, :collect_concat, :inject, :reduce, :partition, :group_by, :all?, :any?, :one?, :none?, :min, :max, :minmax, :min_by, :max_by, :minmax_by, :member?, :each_with_index, :each_entry, :each_slice, :each_cons, :each_with_object, :chunk, :slice_before, :lazy, :m, :nil?, :===, :=~, :!~, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__] irb(main):046:0> nums.length => 9 irb(main):047:0> nums => [1, 2, 3, 4, 17, nil, nil, nil, -8] irb(main):048:0> nums[5,9]=42 => 42 irb(main):049:0> nums => [1, 2, 3, 4, 17, 42] irb(main):050:0> nums[6]="six" => "six" irb(main):051:0> nums => [1, 2, 3, 4, 17, 42, "six"] irb(main):052:0> nums.each {puts "hello"} hello hello hello hello hello hello hello => [1, 2, 3, 4, 17, 42, "six"] irb(main):053:0> nums.each {|n| puts n} 1 2 3 4 17 42 six => [1, 2, 3, 4, 17, 42, "six"] irb(main):054:0> things = {"this" => 42, "that" => 17, "nogots"=>nil} => {"this"=>42, "that"=>17, "nogots"=>nil} irb(main):055:0> things => {"this"=>42, "that"=>17, "nogots"=>nil} irb(main):056:0> things["this"] => 42 irb(main):057:0> things.each { |k, v| puts "key is " + k + " and value is " + v } TypeError: no implicit conversion of Fixnum into String from (irb):57:in `+' from (irb):57:in `block in irb_binding' from (irb):57:in `each' from (irb):57 from /usr/bin/irb:12:in `
' irb(main):058:0> things.each { |k, v| puts "key is " + k + " and value is " + v.to_s } key is this and value is 42 key is that and value is 17 key is nogots and value is => {"this"=>42, "that"=>17, "nogots"=>nil} irb(main):059:0> things.each { |a, b , c| puts a; puts b; puts c} this 42 that 17 nogots => {"this"=>42, "that"=>17, "nogots"=>nil} irb(main):060:0> 10.times { | n | puts n } 0 1 2 3 4 5 6 7 8 9 => 10 irb(main):061:0> 3.times { "have a nice weekend" } => 3 irb(main):062:0> 3.times { puts "have a nice weekend" } have a nice weekend have a nice weekend have a nice weekend => 3 irb(main):063:0>exit exit Script done on Fri Nov 4 14:20:45 2016