Script started on Fri May 5 10:43:19 2023 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.to_s => "1/2" irb(main):004:0> puts half 1/2 => nil irb(main):005:0> gets hi there! => "hi there!\n" irb(main):006:0> Rat.new(1,3) => # irb(main):007:0> third = Rat.new(1,3) => # irb(main):008:0> third => # irb(main):009:0> puts third 1/3 => nil irb(main):010:0> four = Rat.new(4) => # irb(main):011:0> four.to_s => "4" irb(main):012:0> four.add! four => # irb(main):013:0> four => # irb(main):014:0> four.to_s => "8" irb(main):015:0> four = Rat.new(4) => # irb(main):016:0> four + four => # irb(main):017:0> four.+(four) => # irb(main):018:0> four.to_s => "4" irb(main):019:0> four + half => # irb(main):020:0> half + four => # irb(main):021:0> half + 4 NoMethodError: undefined method `num' for 4:Fixnum from Rat.rb:43:in `add!' from Rat.rb:57:in `+' from (irb):21 from /usr/bin/irb:11:in `
' irb(main):022:0> 4 + half TypeError: Rat can't be coerced into Fixnum from (irb):22:in `+' from (irb):22 from /usr/bin/irb:11:in `
' irb(main):026:0> ^D bash-3.2$ irb irb(main):001:0> load "Rat.rb" => true irb(main):003:0> four = Rat.new(4) => # irb(main):004:0> four.double NoMethodError: undefined method `double' for # from (irb):4 from /usr/bin/irb:11:in `
' irb(main):005:0> class Rat irb(main):006:1> def double irb(main):007:2> self.+(self) # self+self also works fine irb(main):008:2> end irb(main):009:1> end => :double irb(main):010:0> four.double => # irb(main):011:0> wrords = [ "hello", "cse", "143" ] => ["hello", "cse", "143"] irb(main):012:0> words [1] => "cse" irb(main):014:0> words[0] = "hi there!"] => "hi there!" irb(main):015:0> words => ["hi there!", "cse", "143"] irb(main):016:0> nums = [1, 2, 3, 4, 5, 6] => [1, 2, 3, 4, 5, 6] irb(main):017:0> nums [4] => 5 irb(main):018:0> nums[10]=9 => 9 irb(main):019:0> nums => [1, 2, 3, 4, 5, 6, nil, nil, nil, nil, 9] irb(main):020:0> nums[11]=10 => 10 irb(main):021:0> nums => [1, 2, 3, 4, 5, 6, nil, nil, nil, nil, 9, 10] irb(main):022:0> nums[-1] => 10 irb(main):023:0> nums[-2] => 9 irb(main):024:0> nums[2,3] => [3, 4, 5] irb(main):025:0> nums[2..4] => [3, 4, 5] irb(main):026:0> nums[2...4] => [3, 4] irb(main):027:0> nums => [1, 2, 3, 4, 5, 6, nil, nil, nil, nil, 9, 10] irb(main):028:0> nums[2..4] = 42 => 42 irb(main):029:0> nums => [1, 2, 42, 6, nil, nil, nil, nil, 9, 10] irb(main):030:0> nums[1..2]=[10,11,12,13,14,15] => [10, 11, 12, 13, 14, 15] irb(main):031:0> nums => [1, 10, 11, 12, 13, 14, 15, 6, nil, nil, nil, nil, 9, 10] irb(main):032:0> nums.class => Array irb(main):033: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):034:0> nums.methods.size => 176 irb(main):035:0> nums.length => 14 irb(main):036:0> nums.push 17 => [1, 10, 11, 12, 13, 14, 15, 6, nil, nil, nil, nil, 9, 10, 17] irb(main):037:0> nums.pop => 17 irb(main):038:0> nums.pop => 10 irb(main):039:0> nums => [1, 10, 11, 12, 13, 14, 15, 6, nil, nil, nil, nil, 9] irb(main):040:0> nums => [1, 10, 11, 12, 13, 14, 15, 6, nil, nil, nil, nil, 9] irb(main):041:0> nums.sort ArgumentError: comparison of NilClass with 9 failed from (irb):41:in `sort' from (irb):41 from /usr/bin/irb:11:in `
' irb(main):042:0> nums[0..5].sort => [1, 10, 11, 12, 13, 14] irb(main):043:0> pets = {"archie" => "cat", "phoebe" => "dog", "bugs" = > "bunny"} => {"archie"=>"cat", "phoebe"=>"dog", "bugs"=>"bunny"} irb(main):044:0> pets["phoebe"] => "dog" irb(main):045:0> pets["archie"] = "CAT!" => "CAT!" irb(main):046:0> pets => {"archie"=>"CAT!", "phoebe"=>"dog", "bugs"=>"bunny"} irb(main):047:0> pets ["bullwinkle"] = "moose" => "moose" irb(main):048:0> pets => {"archie"=>"CAT!", "phoebe"=>"dog", "bugs"=>"bunny", "bullwinkle"=>"moose"} irb(main):049:0> nums => [1, 10, 11, 12, 13, 14, 15, 6, nil, nil, nil, nil, 9] irb(main):050:0> nums.each { |n| puts n } 1 10 11 12 13 14 15 6 9 => [1, 10, 11, 12, 13, 14, 15, 6, nil, nil, nil, nil, 9] irb(main):051: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):052:0> ^D bash-3.2$ exit Script done on Fri May 5 11:21:38 2023