Is it possible to see the ruby code in a proc?

B Seven picture B Seven · Feb 22, 2013 · Viewed 7k times · Source
p = Proc.new{ puts 'ok' }

Is is possible to see the ruby code in the proc?

inspect returns the memory location:

puts p.inspect
#<Proc:0x007f9e42980b88@(irb):2>

Ruby 1.9.3

Answer

Stefan picture Stefan · Feb 22, 2013

Take a look at the sourcify gem:

proc { x + y }.to_source
# >> "proc { (x + y) }"