I am practising with IRB (actually Wirble). I was wondering if any hacking inside IRB could be dumped into a file for later diff-ing, editing and reusing?
You create classes, methods, data on the go, and the interactive session from time to time contains valuable milestones as you evolve with your code - so this would be valuable to reuse in source form.
EDIT: To further clarify the original question: I would like to do this in IRB:
class A; def m1; end; end
class A; def m2; end; end
and then at the end dump class A as
class A
def m1
end
def m2
end
end
(not necessarily pretty-printing the code :-) )
EDIT: Re: @DGM/pry: "pry" seems to be cool, but it's introspection seems to be somewhat buggy, and it does not do what is expected. I did what is above, and the m1 method is not listed if I used show-method A
:
[1] pry(main)> class A; def m1; end; end
=> nil
[2] pry(main)> class A; def m2; end; end
=> nil
[3] pry(main)> show-method A#m1
[...]
class A; def m1; end; end
[4] pry(main)> show-method A#m2
[...]
class A; def m2; end; end
[5] pry(main)> show-method A
[...]
class A; def m2; end; end
EDIT: I have filed a bug report, and @banister was very helpful with the pry issue, see the the ticket, there is very valuable data there.
EDIT: @banister suggested using edit
and it makes sense to follow that workflow.
In Pry, if you create the classes using edit
rather than inside the REPL it should work fine, see the following showterm: