[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Pito Salas

2/2/2009 5:17:00 PM

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

2 Answers

Lars Haugseth

2/3/2009 11:01:00 PM

0

* "R. Pito Salas" <rps@salas.com> wrote:
>
> 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!

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

--
Lars Haugseth

"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

frschoonover

3/26/2011 7:10:00 PM

0

On Mar 25, 11:50 pm, King Size Johnson <bellyfl...@yahoo.com> wrote:
>
> The original was not on green vinyl. Sounds like you got raped on eBay
> again.
>
> P.T. Barnum was right.

KSJ

Looks like that you may be right. Oh well! Live and learn, I suppose.
Still, it does make a nice conversation, though.

Thanks for sharing.Sincerely Frank R.Schoonover