Inspired by Francis Fish's string2file method, I came up with a quick way of dumping any object in IRB to a file. Add this to your ~/.irbrc:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

module SaveToFile
  def to_file(filename="to_s.txt")
    File.open(filename, "w") do |f|
      f << self.to_s
    end
  end
  
  def inspect_to_file(filename="inspect.txt")
    File.open(filename, "w") do |f|
      f << self.inspect
    end
  end
end

Object.class_eval do
  include SaveToFile
end