p = Proc.new{ puts \'ok\' }
Is is possible to see the ruby code in the proc?
inspect
returns the memory location:
No, there is no way to do that in Ruby.
Some Ruby implementations may or may not have implementation-specific ways of getting the source code.
You can also try to use Proc#source_location
to find the file that the Proc
was defined in, and then parse that file to find the source code. But that won't work if the Proc
wasn't defined in a file (e.g. if it was defined dynamically with eval
) or if the source file no longer exists, e.g. because you are running an AOT-compiled version of your program.
So, the short answer is: no, there is no way. The long answer is: there are some ways that may or may not sometimes work depending on way too many factors to even begin to make this work reliably.
That's not even taking into account Proc
s which don't even have a Ruby source code because they were defined in native code.