Say I have this Ruby method:
def get_proc_from_block(&block)
return block
end
Now if I call it with a block like this:
p = get_proc_from_block(&:length)
...is there any way for me to somehow inspect p and get the string "length" from it?
Say I have this Ruby method:
def get_proc_from_block(&block)
return block
end
Now if I call it with a block like this:
p = get_proc_from_block(&:length)
...is there any way for me to somehow inspect p and get the string "length" from it?
Each of the following expressions result in the same regular proc:
get_proc_from_block(&:length)
:length.to_proc
proc{ |a| a.length }
And Ruby doesn't support inspecting their source code. For more detailed answers check out these questions: