[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

list methods only for specific class

tivrfoa

6/15/2009 5:38:00 AM

hello folks!

Is there a way to list methods only for specific class, i.e., not
inherited?

Thank you!
--
Posted via http://www.ruby-....

7 Answers

Daniel Roux

6/15/2009 6:15:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

On Mon, Jun 15, 2009 at 12:38 AM, Le Sa <lescoutinhovr@gmail.com> wrote:

> hello folks!
>
> Is there a way to list methods only for specific class, i.e., not
> inherited?
>
> Thank you!
> --
> Posted via http://www.ruby-....
>

object.public_methods(false)

Hope this helps!
--
Daniel Roux

Robert Klemme

6/15/2009 6:19:00 AM

0

On 15.06.2009 07:38, Le Sa wrote:
> Is there a way to list methods only for specific class, i.e., not
> inherited?

http://ruby-doc.org/core-1.8.7/classes/Module.ht...

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestprac...

tivrfoa

6/15/2009 3:28:00 PM

0

I would like to list ms1 and ms2, but thanks for the help!

class Person
def mp1() end
end

class Student < Person
def ms1() end
def ms2() end

private :ms2
end

Student.public_methods(false).each {|m|puts m}
puts "************\n"
Student.instance_methods(false).each{|m|puts m}
=begin
OUTPUT IS:

yaml_tag_subclasses?
allocate
to_yaml
superclass
new
************
ms1
=end
--
Posted via http://www.ruby-....

tivrfoa

6/15/2009 3:31:00 PM

0

No problem!
instance_methods(false) is fine, because I won't be able to use private
methods anyway xD

Le Sa wrote:
> I would like to list ms1 and ms2, but thanks for the help!


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

Michael Kohl

6/15/2009 3:55:00 PM

0

On Mon, Jun 15, 2009 at 5:27 PM, Le Sa<lescoutinhovr@gmail.com> wrote:
> I would like to list ms1 and ms2, but thanks for the help!
>
> class Person
> =A0def mp1() =A0end
> end
>
> class Student < Person
> =A0def ms1() end
> =A0def ms2() end
>
> =A0private :ms2
> end

The closest I have to offer is this:

>> Student.new.methods - Object.instance_methods
=3D> ["ms1", "mp1"]

Daniel Roux

6/15/2009 4:48:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Mon, Jun 15, 2009 at 10:27 AM, Le Sa <lescoutinhovr@gmail.com> wrote:

> I would like to list ms1 and ms2, but thanks for the help!
>
> class Person
> def mp1() end
> end
>
> class Student < Person
> def ms1() end
> def ms2() end
>
> private :ms2
> end
>
> Student.public_methods(false).each {|m|puts m}
> puts "************\n"
> Student.instance_methods(false).each{|m|puts m}
> =begin
> OUTPUT IS:
>
> yaml_tag_subclasses?
> allocate
> to_yaml
> superclass
> new
> ************
> ms1
> =end
> --
> Posted via http://www.ruby-....
>
>
Try:
Student.new.public_methods(false) + Student.new.private_methods(false)
=> ["ms1", "ms2"]
--
Daniel Roux

Robert Klemme

6/16/2009 7:04:00 AM

0

2009/6/15 Daniel Roux <danielroux@gmail.com>:

> Try:
> Student.new.public_methods(false) + Student.new.private_methods(false)
> => ["ms1", "ms2"]

Why do you folks create instances? You can do this as well:

cl = any_class
cl.instance_methods(false) - cl.private_instance_methods

Kind regards

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestprac...