FInding out the name of the method from which I was called?

Is there a clever meta programming way for me to do this:

def calling_method_1

reporting_method

end

def reporting_method_2

puts “Hey I was just called from #{magic}”

end

and when running reporting_method_2 this prints

Hey I was just called from calling_method_1

Thanks for any pointers!

– Pito

puts “Hey I was just called from #{magic}”

end

def reporting_method
caller.shift
end

Check Kernel#caller.

Jan

def reporting_method_2

puts “Hey I was just called from #{magic}”

end

and when running reporting_method_2 this prints

Hey I was just called from calling_method_1

Thanks for any pointers!

Kernel#caller
http://www.ruby-doc.org/core/classes/Kernel.html#M005955


Lars H.

“If anyone disagrees with anything I say, I am quite prepared not only
to
retract it, but also to deny under oath that I ever said it.” -Tom
Lehrer