"Caleb Clausen" <vikkous / gmail.com> asked:
> So, is there a way to save a set of irb commands that I just typed to
> a file, so they can be rerun later? Better yet, I'd like to save the
> results of the commands too, and check to see if any results have
> changed on a re-run.

I added the following to my ~/.irbrc

module IRB
  def IRB.history; @history; end
  @history = ""
  class WorkSpace
    alias old_evaluate evaluate
    def evaluate(context, statements, file = __FILE__, line = __LINE__)
      result = old_evaluate(context, statements, file, line)
      if /IRB\.history/.match(statements)
        IRB.history << "#{statements.chomp}\n"
      else
        IRB.history << "#{statements.chomp}  #=> #{result.inspect}\n"
      end
      result
    end
  end
end

This will automatically collect your irb session history in the string 
IRB.history. It might look like this:
    a = 1 + 2  #=> 3
    puts a  #=> nil

One difference between this and the history thing on the wiki is that this 
one saves the expected result in a comment after the line. Another is that 
this will save a whole session of commands, whereas the wiki version is for 
persistent history between sessions.

Cheers,
Dave