Is there a way to find the class methods of a class, just like'methods' finds the instance methods?

Discussion in 'Ruby' started by Kenneth McDonald, Sep 26, 2008.

  1. The subject says it all, really.

    Thanks,
    Ken
     
    Kenneth McDonald, Sep 26, 2008
    #1
    1. Advertising

  2. Kenneth McDonald

    Peña, Botp Guest

    Re: Is there a way to find the class methods of a class, just like 'methods' finds the instance methods?

    From: Kenneth McDonald [mailto:]=20
    # Subject: Is there a way to find the class methods of a class,=20
    # just like 'methods' finds the instance methods?
    # The subject says it all, really.


    singleton_methods
     
    Peña, Botp, Sep 26, 2008
    #2
    1. Advertising

  3. Kenneth McDonald

    ara.t.howard Guest

    On Sep 25, 2008, at 9:56 PM, Kenneth McDonald wrote:

    > The subject says it all, really.
    >
    > Thanks,
    > Ken




    p Class.methods

    p File.methods

    a @ http://codeforpeople.com/
    --
    we can deny everything, except that we have the possibility of being
    better. simply reflect on that.
    h.h. the 14th dalai lama
     
    ara.t.howard, Sep 26, 2008
    #3
  4. Kenneth McDonald

    Peña, Botp Guest

    Re: Is there a way to find the class methods of a class, just like 'methods' finds the instance methods?

    #=20
    # singleton_methods
    #=20

    also,

    methods(false)=20


    tend to always forget this, as false option is not documented in =
    (fast)ri nor ruby-doc

    i'm guessing stefan's docu patch did not make it =
    http://groups.google.com/group/ruby-talk-google/browse_thread/thread/9ab2=
    6673460e61c6

    using 1.8.7/1.9
     
    Peña, Botp, Sep 26, 2008
    #4
  5. Kenneth McDonald wrote:
    > Is there a way to find the class methods of a class, just like 'methods'
    > finds the instance methods?


    methods does not give you the instance methods of a class. instance_methods
    does. obj.methods (where obj might very well be a class) gives you all the
    methods defined on obj, i.e. the instance methods of obj's class (minus the
    ones you undefined for obj specifically, I suppose) + the singleton methods
    that are defined on obj directly. If you specify the argument false, only the
    singleton methods are listed.
    So SomeClass.methods will list all the instance methods of class Class + all
    the singleton (a.k.a. class-)methods of SomeClass and SomeClass.methods(false)
    will give you only the latter.

    HTH,
    Sebastian
    --
    Jabber:
    ICQ: 205544826
     
    Sebastian Hungerecker, Sep 26, 2008
    #5
  6. Thanks everyone. It appears, then, that Ncurses.init_pair is not
    defined in the ncurses module,
    regardless of what the ruby cookbook says. Sigh.

    Ken
    On Sep 26, 2008, at 2:58 AM, Sebastian Hungerecker wrote:

    > Kenneth McDonald wrote:
    >> Is there a way to find the class methods of a class, just like
    >> 'methods'
    >> finds the instance methods?

    >
    > methods does not give you the instance methods of a class.
    > instance_methods
    > does. obj.methods (where obj might very well be a class) gives you
    > all the
    > methods defined on obj, i.e. the instance methods of obj's class
    > (minus the
    > ones you undefined for obj specifically, I suppose) + the singleton
    > methods
    > that are defined on obj directly. If you specify the argument false,
    > only the
    > singleton methods are listed.
    > So SomeClass.methods will list all the instance methods of class
    > Class + all
    > the singleton (a.k.a. class-)methods of SomeClass and
    > SomeClass.methods(false)
    > will give you only the latter.
    >
    > HTH,
    > Sebastian
    > --
    > Jabber:
    > ICQ: 205544826
    >
     
    Kenneth McDonald, Sep 26, 2008
    #6
    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. Tim Verstraete
    Replies:
    1
    Views:
    584
    Mike Treseler
    Sep 12, 2005
  2. walterbyrd
    Replies:
    1
    Views:
    377
    Damjan
    Apr 10, 2006
  3. Joe Butler
    Replies:
    2
    Views:
    341
    mrcakey
    Sep 24, 2007
  4. Brian Vanderburg II
    Replies:
    9
    Views:
    303
  5. Avner
    Replies:
    8
    Views:
    733
    Sisyphus
    Feb 23, 2006
Loading...

Share This Page