getting method names for a Class

Discussion in 'Ruby' started by Mark Volkmann, Feb 10, 2006.

  1. There are so many methods in Object and Module that return arrays of
    method names that it can be a bit confusing. Here's a summary of my
    current understanding. Is any of this wrong?

    "instance_methods" is a method from Module.
    Pass it true to include inherited methods (the default) and false to
    exclude them.
    To get the names of public *instance* methods in the class Foo, use
    Foo.instance_methods.

    "methods" is a method from Object.
    Pass it true to get instance methods (the default) and false to get
    singleton methods.
    A singleton method on a Ruby Class is essentially like a static method in J=
    ava.
    To get the names of public *class* methods in the class Foo, use
    Foo.methods(false).

    Foo.methods(false) =3D=3D Foo.singleton_methods(false)

    Why doesn't Foo.methods(true) return the same thing as
    Foo.instance_methods(true)?

    I can see using a boolean parameter to tell whether you want inherited
    methods to be included (as in the instance_methods method). However,
    using a boolean parameter to tell whether you want instance or
    singleton methods (as in the method "methods") seems bad. Maybe that
    should be deprecated in favor of instance_methods and
    singleton_methods.

    --
    R. Mark Volkmann
    Partner, Object Computing, Inc.
     
    Mark Volkmann, Feb 10, 2006
    #1
    1. Advertising

  2. D=C5=88a Piatok 10 Febru=C3=A1r 2006 16:46 Mark Volkmann nap=C3=ADsal:
    > There are so many methods in Object and Module that return arrays of
    > method names that it can be a bit confusing. Here's a summary of my
    > current understanding. Is any of this wrong?
    >
    > "instance_methods" is a method from Module.
    > Pass it true to include inherited methods (the default) and false to
    > exclude them.
    > To get the names of public *instance* methods in the class Foo, use
    > Foo.instance_methods.
    >
    > "methods" is a method from Object.
    > Pass it true to get instance methods (the default) and false to get
    > singleton methods.
    > A singleton method on a Ruby Class is essentially like a static method in
    > Java. To get the names of public *class* methods in the class Foo, use
    > Foo.methods(false).
    >
    > Foo.methods(false) =3D=3D Foo.singleton_methods(false)
    >
    > Why doesn't Foo.methods(true) return the same thing as
    > Foo.instance_methods(true)?
    >
    > I can see using a boolean parameter to tell whether you want inherited
    > methods to be included (as in the instance_methods method). However,
    > using a boolean parameter to tell whether you want instance or
    > singleton methods (as in the method "methods") seems bad. Maybe that
    > should be deprecated in favor of instance_methods and
    > singleton_methods.
    >
    > --
    > R. Mark Volkmann
    > Partner, Object Computing, Inc.


    Because #instance_methods shows methods an instance of Foo will have, and=20
    #methods and #singleton_methods show you methods of the class object Foo?=20
    Just a guess there.

    David Vallner
     
    David Vallner, Feb 10, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ares Lagae
    Replies:
    8
    Views:
    455
    Ares Lagae
    Sep 24, 2004
  2. John Lenton
    Replies:
    0
    Views:
    382
    John Lenton
    Jan 11, 2005
  3. Mitko Haralanov
    Replies:
    17
    Views:
    433
    Ben Finney
    Oct 20, 2006
  4. Shashank Date

    getting method names

    Shashank Date, Nov 28, 2003, in forum: Ruby
    Replies:
    2
    Views:
    113
    Shashank Date
    Nov 28, 2003
  5. Hunt Jon
    Replies:
    2
    Views:
    121
    Phlip
    Dec 18, 2008
Loading...

Share This Page