# # Enable saving of expression history across runs of irb, just like in ghci # require 'irb/ext/save-history' # History configuration IRB.conf[:SAVE_HISTORY] = 500 IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history" # # Makes "it" work like in ghci. (But _ works, too.) def it IRB.CurrentContext.last_value end def rv RUBY_VERSION end def show_match(s, re) if s =~ re then "#{$`}<<#{$&}>>#{$'}" else "no match" end end alias sm show_match def smg(s, re) if s =~ re then groups = "" sep = "" 1.upto(20) { |n| if $~[n] groups += "#{sep}$#{n} = <<#{$~[n]}>>" sep = ", " end } p "#{$`}<<#{$&}>>#{$'}" puts groups if !groups.empty? true else puts "no match" false end end alias l load # # Some handy globals for assignments 4 and 5 $lg="longest.rb" $sw="seqwords.rb" $mm="minmax.rb" $xf="xfield.rb" $nz="nzip.rb" $vr="vrepl.rb" $mr="mirror.rb" $cc="calc.rb" $sd="switched.rb" $pk="pancakes.rb" # # mainthing simply PRINTS A LINE to remind you how the unless modifier can be used # to prevent starting main when a file is loaded with irb -r. # def maintrick puts 'main unless $0 == "irb"' end alias mainthing maintrick