[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

listing Object.methods

Alex Combas

1/28/2006 9:39:00 AM

Hello,
Tonight I was thinking that it would be handy to
have a way to list all the methods in a class but
not list any of the standard methods that it inherits
from its parent object enless they have been added
to by the class in question.

Something like this, but better.

`Foo.new.methods - Object.methods`

For example if Foo reimplenents .to_s then I would like to know about it.

--
Alex Combas
http://noodlejunkie.blo...


4 Answers

ES

1/28/2006 9:53:00 AM

0

On 2006.01.28 18:39, Alex Combas wrote:
> Hello,
> Tonight I was thinking that it would be handy to
> have a way to list all the methods in a class but
> not list any of the standard methods that it inherits
> from its parent object enless they have been added
> to by the class in question.
>
> Something like this, but better.
>
> `Foo.new.methods - Object.methods`

As a workaround, you can do this:

class << foo; self; end.instance_methods false

> For example if Foo reimplenents .to_s then I would like to know about it.
>
> Alex Combas


E


James Gray

1/28/2006 4:13:00 PM

0

On Jan 28, 2006, at 3:52 AM, Eero Saynatkari wrote:

> On 2006.01.28 18:39, Alex Combas wrote:
>> Something like this, but better.
>>
>> `Foo.new.methods - Object.methods`
>
> As a workaround, you can do this:
>
> class << foo; self; end.instance_methods false

Do we really need a singleton class for that? I prefer:

self.class.instance_methods(false)

James Edward Gray II


Jeff Schwab

1/28/2006 6:03:00 PM

0

James Edward Gray II wrote:
> On Jan 28, 2006, at 3:52 AM, Eero Saynatkari wrote:
>
>> On 2006.01.28 18:39, Alex Combas wrote:
>>
>>> Something like this, but better.
>>>
>>> `Foo.new.methods - Object.methods`
>>
>>
>> As a workaround, you can do this:
>>
>> class << foo; self; end.instance_methods false
>
>
> Do we really need a singleton class for that? I prefer:
>
> self.class.instance_methods(false)

Wow. I'm still new to Ruby, but I've gotta say, I am rapidly becoming
more enthusiastic.

ES

1/28/2006 9:09:00 PM

0

On 2006.01.29 01:13, James Edward Gray II wrote:
> On Jan 28, 2006, at 3:52 AM, Eero Saynatkari wrote:
>
> >On 2006.01.28 18:39, Alex Combas wrote:
> >>Something like this, but better.
> >>
> >>`Foo.new.methods - Object.methods`
> >
> >As a workaround, you can do this:
> >
> > class << foo; self; end.instance_methods false
>
> Do we really need a singleton class for that? I prefer:
>
> self.class.instance_methods(false)

Yep, otherwise singleton methods will not be included.

> James Edward Gray II


E