[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: getting method names

Gavri Savio Fernandez

11/28/2003 6:58:00 PM

> From: Shashank Date [mailto:sdate@everestkc.net]
> Subject: getting method names
>
>
> How do I get the name of the missing method inside the
> missing_method
> method?
>
> class Foo
> def missing_method(*args)
> puts " <#{???}> method is not yet implemented"
> # ^^^^^^ What should I put here?
> end
> end
>
> f = Foo.new
> f.boo # This should print "<boo> method is not yet implemented"

From the pragmatic programmer's guide:

##################################################################
method_missing obj.method_missing( aSymbol [, *args ] ) -> anObject
Invoked by Ruby when obj is sent a message it cannot handle. aSymbol is the symbol for the method called, and args are any arguments that were passed to it.
###################################################################

#code sample start
class Foo
def method_missing(s, *args)
puts s
end
end
f = Foo.new
f.random_name
#code sample end

when executed this gives

random_name

as output

>
> TIA,
> -- shanko
>

Gavri Savio Fernandez
___________________________________________

If only God would give me some clear sign! Like making a large deposit in my name at a Swiss bank. - Woody Allen

1 Answer

Shashank Date

11/28/2003 8:24:00 PM

0


"Gavri Savio Fernandez" <Gavri_F@infosys.com> wrote in message
> From the pragmatic programmer's guide:
>
> #########################################################
> method_missing obj.method_missing( aSymbol [, *args ] ) -> anObject
> Invoked by Ruby when obj is sent a message it cannot handle.

I knew about this but somehow just spaced out.
Thanks for the prompt response.
-- shanko