Script started on Fri May 7 10:18:26 2021 bash-3.2$ irb irb(main):001:0> load "Rat.rb" => true irb(main):002:0> half = Rat.new(4,8) => # irb(main):003:0> half => # irb(main):004:0> half.to_s => "1/2" irb(main):005:0> puts half 1/2 => nil irb(main):006:0> gets hello => "hello\n" irb(main):007:0> third = Rat.new (1,3) => # irb(main):008:0> four = Rat.new(4) => # irb(main):009:0> puts third 1/3 => nil irb(main):010:0> puts four 4 => nil irb(main):011:0> four + half => # irb(main):012:0> puts four + half 9/2 => nil irb(main):013:0> half+two NameError: undefined local variable or method `two' for main:Object from (irb):13 from /usr/bin/irb:11:in `
' irb(main):014:0> half+four => # irb(main):015:0> half+4 NoMethodError: undefined method `num' for 4:Fixnum from Rat.rb:43:in `add!' from Rat.rb:57:in `+' from (irb):15 from /usr/bin/irb:11:in `
' irb(main):016:0> 4+half TypeError: Rat can't be coerced into Fixnum from (irb):16:in `+' from (irb):16 from /usr/bin/irb:11:in `
' irb(main):017:0> words = "hello" "cse" "413" ] => ["hellocse413"] irb(main):018:0> nums [ 1, 2, 3, 4 ] NoMethodError: undefined method `nums' for main:Object from (irb):18 from /usr/bin/irb:11:in `
' irb(main):019:0> nums = [1,2,3,4] => [1, 2, 3, 4] irb(main):020:0> words => ["hellocse413"] irb(main):021:0> nums => [1, 2, 3, 4] irb(main):022:0> words = [ "hello", "cse" , "413" ] => ["hello", "cse", "413"] irb(main):023:0> words => ["hello", "cse", "413"] irb(main):024:0> nums[3] => 4 irb(main):025:0> nums[1]=17 => 17 irb(main):026:0> nums => [1, 17, 3, 4] irb(main):027:0> nums[10]= "ten" => "ten" irb(main):028:0> nums => [1, 17, 3, 4, nil, nil, nil, nil, nil, nil, "ten"] irb(main):029:0> nums[-7] => nil irb(main):030:0> nums[-9] => 3 irb(main):031:0> nums[-1] => "ten" irb(main):032:0> nums[1,2] => [17, 3] irb(main):033:0> nums[1..3] => [17, 3, 4] irb(main):034:0> nums[4,10]=42 => 42 irb(main):035:0> nums => [1, 17, 3, 4, 42] irb(main):036:0> nums[1,2]=[7,8,9,10] => [7, 8, 9, 10] irb(main):037:0> nums => [1, 7, 8, 9, 10, 4, 42] irb(main):038:0> nums.class => Array irb(main):039:0> nums.methods => [:keep_if, :values_at, :delete_at, :delete_if, :reject!, :transpose, :fill, :assoc, :rassoc, :to_h, :uniq, :uniq!, :compact, :include?, :flatten, :shuffle!, :shuffle, :flatten!, :compact!, :permutation, :combination, :repeated_combination, :product, :repeated_permutation, :bsearch, :bsearch_index, :sample, :rotate!, :&, :*, :+, :-, :sort, :count, :find_index, :select, :reject, :collect, :map, :first, :any?, :pack, :reverse_each, :zip, :take, :take_while, :drop, :drop_while, :cycle, :insert, :|, :index, :rindex, :replace, :clear, :<=>, :<<, :==, :[], :[]=, :empty?, :eql?, :reverse!, :reverse, :concat, :inspect, :delete, :length, :size, :each, :slice, :slice!, :to_ary, :to_a, :to_s, :dig, :hash, :at, :fetch, :frozen?, :last, :push, :pop, :shift, :unshift, :join, :rotate, :each_index, :sort!, :sort_by!, :collect!, :map!, :select!, :find, :entries, :sort_by, :grep, :grep_v, :detect, :find_all, :flat_map, :collect_concat, :inject, :reduce, :partition, :group_by, :all?, :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, :slice_after, :slice_when, :chunk_while, :lazy, :tap, :public_send, :instance_variables, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :private_methods, :kind_of?, :is_a?, :instance_variable_get, :method, :public_method, :singleton_method, :instance_of?, :extend, :define_singleton_method, :to_enum, :enum_for, :===, :=~, :!~, :respond_to?, :freeze, :object_id, :display, :send, :nil?, :class, :singleton_class, :clone, :dup, :itself, :taint, :tainted?, :untaint, :untrust, :trust, :untrusted?, :methods, :protected_methods, :public_methods, :singleton_methods, :!, :!=, :__send__, :equal?, :instance_eval, :instance_exec, :__id__] irb(main):040:0> nums.methods.class => Array irb(main):041:0> nums => [1, 7, 8, 9, 10, 4, 42] irb(main):042:0> nums.sort => [1, 4, 7, 8, 9, 10, 42] irb(main):043:0> nums.methods.length => 176 irb(main):044:0> nums.length => 7 irb(main):045:0> nums => [1, 7, 8, 9, 10, 4, 42] irb(main):046:0> nums.each { puts "another num" } another num another num another num another num another num another num another num => [1, 7, 8, 9, 10, 4, 42] irb(main):047:0> nums.each { |n| puts n } 1 7 8 9 10 4 42 => [1, 7, 8, 9, 10, 4, 42] irb(main):048:0> things = { "this" => 42, "that" => 17, "nogot" => nil } => {"this"=>42, "that"=>17, "nogot"=>nil} irb(main):049:0> things["that"] => 17 irb(main):050:0> things["missing"] => nil irb(main):051:0> things["num"] = "num" => "num" irb(main):052:0> things => {"this"=>42, "that"=>17, "nogot"=>nil, "num"=>"num"} irb(main):053:0> things.each { puts "another entry" } another entry another entry another entry another entry => {"this"=>42, "that"=>17, "nogot"=>nil, "num"=>"num"} irb(main):054:0> things.each { |k,v| puts "key is " + k + " and value is " + v } TypeError: no implicit conversion of Fixnum into String from (irb):54:in `+' from (irb):54:in `block in irb_binding' from (irb):54:in `each' from (irb):54 from /usr/bin/irb:11:in `
' irb(main):055:0> things.each { |k,v| puts "key is " + k.to_s + " and value is " + v.to_s } key is this and value is 42 key is that and value is 17 key is nogot and value is key is num and value is num => {"this"=>42, "that"=>17, "nogot"=>nil, "num"=>"num"} irb(main):056:0> 10.times { puts "have a great weekend" } have a great weekend have a great weekend have a great weekend have a great weekend have a great weekend have a great weekend have a great weekend have a great weekend have a great weekend have a great weekend => 10 irb(main):057:0> ^D bash-3.2$ exit Script done on Fri May 7 11:25:00 2021