[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Get only the non-inherited methods of a class

Yukihiro Matsumoto

11/2/2007 1:14:00 PM

Hi,

In message "Re: Get only the non-inherited methods of a class"
on Fri, 2 Nov 2007 21:05:57 +0900, Max Williams <toastkid.williams@gmail.com> writes:

|Does anyone know how to get the methods of a class in such a way as to
|*not* get inherited ones?

Giving false to #methods.

Stringh.methods
=> ["inspect", "send", "class_eval",...
String.methods(false)
=> []



matz.

2 Answers

Robert Klemme

11/2/2007 1:22:00 PM

0

2007/11/2, Yukihiro Matsumoto <matz@ruby-lang.org>:
> Hi,
>
> In message "Re: Get only the non-inherited methods of a class"
> on Fri, 2 Nov 2007 21:05:57 +0900, Max Williams <toastkid.williams@gmail.com> writes:
>
> |Does anyone know how to get the methods of a class in such a way as to
> |*not* get inherited ones?
>
> Giving false to #methods.
>
> Stringh.methods
> => ["inspect", "send", "class_eval",...
> String.methods(false)
> => []

I guess when invoked on the class instance then it should probably be
String.instance_methods and String.instance_methods(false). If
invoked on the instance then methods and methods(false) should be
appropriate.

Kind regards

robert

--
use.inject do |as, often| as.you_can - without end

Max Williams

11/2/2007 1:29:00 PM

0

Yukihiro Matsumoto wrote:

> Giving false to #methods.
>
> Stringh.methods
> => ["inspect", "send", "class_eval",...
> String.methods(false)
> => []

Thanks matz, but why does that return an empty array? Shouldn't it be

["%", "*", "+", "<<", etc]?

(actually for me it returns ["yaml_new", "yaml_tag_subclasses?"], each
of which gives me a NoMethodError when i try to call it on a string)

Would you mind explaining what passing false to methods does?

thanks!
--
Posted via http://www.ruby-....