Dumb question: in documentation, why Object#method, and not Object.method ?

Discussion in 'Ruby' started by Elf M. Sternberg, Nov 30, 2005.

  1. I keep seeing this syntax in documentation: Object#method, but in actual
    use sending a message to an object is usually

    object = Object.new
    object.method

    Is this just to emphasize that method() operates on an instance of
    Object and not the class Object?

    Elf
    Elf M. Sternberg, Nov 30, 2005
    #1
    1. Advertising

  2. Re: Dumb question: in documentation, why Object#method, and not Object.method?

    Elf M. Sternberg wrote:
    > I keep seeing this syntax in documentation: Object#method, but in actual
    > use sending a message to an object is usually
    >
    > object = Object.new
    > object.method
    >
    > Is this just to emphasize that method() operates on an instance of
    > Object and not the class Object?


    Yes.
    Bob Showalter, Nov 30, 2005
    #2
    1. Advertising

  3. Re: Dumb question: in documentation, why Object#method, and not Object.method?

    Elf M. Sternberg wrote:
    > I keep seeing this syntax in documentation: Object#method, but in actual
    > use sending a message to an object is usually
    >
    > object = Object.new
    > object.method
    >
    > Is this just to emphasize that method() operates on an instance of
    > Object and not the class Object?


    Yes.
    Jeffrey Schwab, Nov 30, 2005
    #3
  4. Elf M. Sternberg

    Trans Guest

    Yes. ;-)
    Trans, Nov 30, 2005
    #4
  5. On 11/30/05, Elf M. Sternberg <> wrote:
    > I keep seeing this syntax in documentation: Object#method, but in actual
    > use sending a message to an object is usually
    >
    > object =3D Object.new
    > object.method
    >
    > Is this just to emphasize that method() operates on an instance of
    > Object and not the class Object?


    As others have said, yes. As I understand it, though, it's a smalltalkism.

    -austin
    --
    Austin Ziegler *
    * Alternate:
    Austin Ziegler, Nov 30, 2005
    #5
  6. Elf M. Sternberg

    Trans Guest

    Notice that "Object" in "Object#method" is capitalized. We're talking
    about a class here not an instance. So if you were to say Object.method
    you'd be refering to an instance method of the class itself --generally
    called a _class method_, as opposed to an instance method defined by
    the class. It's tricky because its relative --a class is itself an
    instance of Class.

    HTH,
    T.
    Trans, Nov 30, 2005
    #6
  7. Re: Dumb question: in documentation, why Object#method, and notObject.method ?

    Hi --

    On Thu, 1 Dec 2005, Marcel Molina Jr. wrote:

    > On Thu, Dec 01, 2005 at 04:17:30AM +0900, Elf M. Sternberg wrote:
    >> I keep seeing this syntax in documentation: Object#method, but in actual
    >> use sending a message to an object is usually
    >>
    >> object = Object.new
    >> object.method
    >>
    >> Is this just to emphasize that method() operates on an instance of
    >> Object and not the class Object?

    >
    > The # is a naming convention.
    >
    > Class#method means method is an instance method.
    > Class::method means method is a class method.
    >
    > For example, do
    >
    > ri IO.read
    >
    > There is IO::read and IO#read.


    Interesting -- I never picked up on ri's use of :: in preference to
    the dot. I personally use Class.method for class methods (indeed for
    any singleton method).


    David

    --
    David A. Black
    David A. Black, Nov 30, 2005
    #7
  8. Re: Dumb question: in documentation, why Object#method, and not Object.method?

    David A. Black wrote:
    > Hi --
    >
    > On Thu, 1 Dec 2005, Marcel Molina Jr. wrote:
    >
    >> On Thu, Dec 01, 2005 at 04:17:30AM +0900, Elf M. Sternberg wrote:
    >>> I keep seeing this syntax in documentation: Object#method, but in actual
    >>> use sending a message to an object is usually
    >>>
    >>> object = Object.new
    >>> object.method
    >>>
    >>> Is this just to emphasize that method() operates on an instance of
    >>> Object and not the class Object?

    >>
    >> The # is a naming convention.
    >>
    >> Class#method means method is an instance method.
    >> Class::method means method is a class method.
    >>
    >> For example, do
    >>
    >> ri IO.read
    >>
    >> There is IO::read and IO#read.

    >
    > Interesting -- I never picked up on ri's use of :: in preference to
    > the dot. I personally use Class.method for class methods (indeed for
    > any singleton method).


    I believe that to be the convention, too.

    Klass.method <- Class method
    Klass#method <- Instance method
    Klass::FOO <- Class constant
    Klass::AnotherKlass <- Class constant (class or module)
    Daniel Schierbeck, Nov 30, 2005
    #8
  9. Elf M. Sternberg

    jwesley Guest

    Hmm...so Class is an instance of itself?
    jwesley, Dec 1, 2005
    #9
  10. Elf M. Sternberg

    MenTaLguY Guest

    Re: Dumb question: in documentation, why Object#method, and notObject.method ?

    --=-q8vfd9xedR+DKdFV5gsp
    Content-Type: text/plain
    Content-Transfer-Encoding: quoted-printable

    On Fri, 2005-12-02 at 00:37 +0900, jwesley wrote:
    > Hmm...so Class is an instance of itself?


    Yep.

    Class.class # =3D> Class

    -mental

    --=-q8vfd9xedR+DKdFV5gsp
    Content-Type: application/pgp-signature; name=signature.asc
    Content-Description: This is a digitally signed message part

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.1 (GNU/Linux)

    iD8DBQBDjxnXcUNIGiXCc4MRAhyKAJ0eaGve1rgrwoS/XW4Il+PtPpQmdACeMsES
    Vbzhr417GcdyR5ctRonjM8w=
    =0fD5
    -----END PGP SIGNATURE-----

    --=-q8vfd9xedR+DKdFV5gsp--
    MenTaLguY, Dec 1, 2005
    #10
  11. Re: Dumb question: in documentation, why Object#method, and notObject.method ?

    Hi --

    On Fri, 2 Dec 2005, jwesley wrote:

    > Hmm...so Class is an instance of itself?


    Yes. And Object is a Class, and Class is an Object :) Ruby
    object-space chases its own tail a bit at the top of the hierarchy,
    for the sake of bootstrapping itself into existence.


    David

    --
    David A. Black
    David A. Black, Dec 1, 2005
    #11
  12. Elf M. Sternberg

    Gary Leydon Guest

    dumb question...where is Object#method usage documented

    elf wrote:
    > I keep seeing this syntax in documentation: Object#method, but in actual
    > use sending a message to an object is usually
    >
    > object = Object.new
    > object.method
    >
    > Is this just to emphasize that method() operates on an instance of
    > Object and not the class Object?
    >
    > Elf


    Where is this documented? I can't find it in any book...and searching
    google on Ruby object#method doesn't lead to an explanation of this. You
    get reams of hits using object#method syntax but not where it comes
    from.

    --
    Posted via http://www.ruby-forum.com/.
    Gary Leydon, Jul 28, 2009
    #12
  13. Elf M. Sternberg

    James Coglan Guest

    Re: dumb question...where is Object#method usage documented

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

    2009/7/28 Gary Leydon <>

    > elf wrote:
    > > I keep seeing this syntax in documentation: Object#method, but in actual
    > > use sending a message to an object is usually
    > >
    > > object = Object.new
    > > object.method
    > >
    > > Is this just to emphasize that method() operates on an instance of
    > > Object and not the class Object?
    > >
    > > Elf

    >
    > Where is this documented? I can't find it in any book...and searching
    > google on Ruby object#method doesn't lead to an explanation of this. You
    > get reams of hits using object#method syntax but not where it comes
    > from.



    http://ruby-doc.org/core/classes/Object.html#M000336

    --
    James Coglan
    http://jcoglan.com
    James Coglan, Jul 28, 2009
    #13
  14. Elf M. Sternberg

    Codeblogger Guest

    Re: dumb question...where is Object#method usage documented

    >
    > Where is this documented? I can't find it in any book...and searching
    > google on Ruby object#method doesn't lead to an explanation of this.


    I immediately found it on ruby-doc.org:
    http://www.ruby-doc.org/core/classes/Object.html#M000336

    Regards
    Nicolai
    Codeblogger, Jul 28, 2009
    #14
  15. Elf M. Sternberg

    gb le Guest

    found it...where is Object#method usage documented

    Nicolai Reuschling wrote:
    >>
    >> Where is this documented? I can't find it in any book...and searching
    >> google on Ruby object#method doesn't lead to an explanation of this.

    >
    > I immediately found it on ruby-doc.org:
    > http://www.ruby-doc.org/core/classes/Object.html#M000336
    >
    > Regards
    > Nicolai


    Thanks for taking the time, I suspect I didn't make my question
    clear,there is nothing that I can see on the link Object.html#M000336
    that specifies what object#method means vs object::method but your link
    lead me to search on the site and I found it here
    http://ruby-doc.org/documentation-guidelines.html, somewhat buried but
    certainly clear.

    Style Guidelines

    Use :: for describing class methods,
    # for describing instance methods,
    . for example code.
    --
    Posted via http://www.ruby-forum.com/.
    gb le, Jul 28, 2009
    #15
  16. Re: dumb question...where is Object#method usage documented

    Gary Leydon schrieb:
    > elf wrote:
    >> I keep seeing this syntax in documentation: Object#method, but in actual
    >> use sending a message to an object is usually
    >>
    >> object = Object.new
    >> object.method
    >>
    >> Is this just to emphasize that method() operates on an instance of
    >> Object and not the class Object?
    >>
    >> Elf

    >
    > Where is this documented? I can't find it in any book...and searching
    > google on Ruby object#method doesn't lead to an explanation of this. You
    > get reams of hits using object#method syntax but not where it comes
    > from.


    The 1st edition of "Programming Ruby"[1] (a.k.a. the "Pickaxe") mentions
    this notation:
    > Within the text, Fred#doIt is a reference to an instance method (doIt) of
    > class Fred, while Fred.new [In some other Ruby documentation, you may
    > see class methods written as Fred::new. This is perfectly valid Ruby
    > syntax; we just happen to feel that Fred.new is less distracting to
    > read.] is a class method, and Fred::EOF is a class constant.


    The first appearance in the Ruby changelog[2] dates back to 1995,
    suggesting that Matz himself may have introduced this convention.

    -Matthias

    [1]: http://www.rubycentral.com/pickaxe/preface.html
    [2]:
    http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/tags/v1_0/ChangeLog?revision=2&view=markup
    Matthias Reitinger, Jul 29, 2009
    #16
    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. El Guerrero del Interfaz

    Dumb question: How do I get an object's parent?

    El Guerrero del Interfaz, Jun 9, 2005, in forum: Java
    Replies:
    2
    Views:
    299
    Steve Horsley
    Jun 9, 2005
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    838
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,666
    Smokey Grindel
    Dec 2, 2006
  4. Marc Wilson

    Dumb newbie question- object references

    Marc Wilson, Nov 25, 2003, in forum: Javascript
    Replies:
    4
    Views:
    117
    Marc Wilson
    Nov 26, 2003
  5. Jerry C.
    Replies:
    8
    Views:
    201
    Uri Guttman
    Nov 23, 2003
Loading...

Share This Page