Professional Web Applications Themes

Silly question - Ruby

All: This may be mentioned somewhere, but I have yet to see an explanation of what the difference between: Class#method and Class.method is in the doentation. For instance, in the ProgrammingRuby.chm that is shipped with Ruby the following two references were found (both on same page): IO#each_byte and IO.foreach I don't suspect it's a big deal, however, not knowing is really nagging at me. :) Regards, Brad...

  1. #1

    Default Silly question

    All:

    This may be mentioned somewhere, but I have yet to see an explanation
    of what the difference between:

    Class#method

    and

    Class.method

    is in the doentation.


    For instance, in the ProgrammingRuby.chm that is shipped with Ruby
    the following two references were found (both on same page):

    IO#each_byte

    and

    IO.foreach

    I don't suspect it's a big deal, however, not knowing is really
    nagging at me. :)


    Regards,
    Brad
    Brad Guest

  2. #2

    Default Re: Silly question

    Based on your two methods there, I'd say that the person writing means

    Class#method

    to be an instance method, while

    Class.method

    is a class method. However, I'm not sure that it's used that way in
    general.

    Around here, from what I've gathered, # is simply a prefix that means
    "the following word is a method." So if I'm talking about the foo
    method, I'd say #foo. That way you know it's a method. It'd be sort
    of like writing foo() when talking about C.

    - Dan


    Dan Guest

  3. #3

    Default Re: Silly question

    On Tuesday, February 3, 2004, 1:19:57 AM, Brad wrote:
     
     
     
     
     
     


    Class#instance_method (Array#size)

    Class.class_method (Regexp.escape)

    Class methods are really just singleton methods on a class object.
    That's why I prefer Class.method notation to Class::method, which is
    also allowed.

    Class#method is a doentation convention only; the language does not
    recognise it.

    Cheers,
    Gavin



    Gavin Guest

  4. #4

    Default Re: Silly question

    Dan Doel wrote:
     
    Dan:

    Thanks for the response! Now that I know, everytime I look something
    up in the ProgrammingRuby.chm I won't get that nagging feeling. :)

    Thanks,
    Brad

    Brad Guest

  5. #5

    Default Re: Silly question

    Gavin Sinclair wrote:
     





    >
    >
    > Class#instance_method (Array#size)
    >
    > Class.class_method (Regexp.escape)
    >
    > Class methods are really just singleton methods on a class object.
    > That's why I prefer Class.method notation to Class::method, which is
    > also allowed.
    >
    > Class#method is a doentation convention only; the language does not
    > recognise it.
    >
    > Cheers,
    > Gavin
    >
    >
    >[/ref]
    Gavin:

    Hey thanks for the reply! I kind of figured that the use of '#' between
    a class and a method was only a doentation convention. But it wasn't
    clear what the notation was used to mean. i.e. both # and . were used,
    but without explanation of the difference. :)

    It's been mentioned that the use of # signifies an instance method and
    the use of . signifies a class method. (Thanks to Dan Doel for this
    explanation) Though, as Dan said, it's unclear if this is the actual
    difference between the two symbols.

    Thanks,
    Brad
    Brad Guest

  6. #6

    Default Re: Silly question


    On Feb 2, 2004, at 8:19, Brad wrote:
     

    It's a way of distinguishing between an instance method and a class
    method in the doentation. When we say IO#each_byte, we're referring
    to an instance method of class IO, whereas IO.foreach is a class
    method.

    I personally don't like to convention too much, but I'm not sure I can
    think of a better one.

    Cheers

    Dave



    Dave Guest

  7. #7

    Default Re: Silly question

    --Apple-Mail-12-791042086
    Content-Transfer-Encoding: 7bit
    Content-Type: text/plain;
    cht=US-ASCII;
    format=flowed


    On Feb 2, 2004, at 8:59, Brad wrote:
     

    From the preface:

    Notation Conventions

    Throughout this book, we use the following typographic notations.
    . .
    Within the text, Fred#doIt is a reference to an instance method (doIt)
    of class Fred, while Fred.new is a class method, and Fred::EOF is a
    class constant



    Cheers

    Dave

    --Apple-Mail-12-791042086--


    Dave Guest

  8. #8

    Default Re: Silly question

    Dave Thomas wrote:
     
    >
    >
    > From the preface:
    >
    >
    > Notation Conventions
    >
    >
    > Throughout this book, we use the following typographic notations.
    > . .
    > Within the text, Fred#doIt is a reference to an instance method (doIt)
    > of class Fred, while Fred.new is a class method, and Fred::EOF is a
    > class constant
    >
    >
    >
    >
    > Cheers
    >
    >
    > Dave
    >
    >
    >[/ref]
    Dave:

    Thank you for your response, it's appreciated.

    I didn't see that text before, honest. Thank you for pointing it out
    and I'm sorry for wasting everyone's time with such a silly question.

    Thanks again.

    Regards,
    Brad
    Brad Guest

  9. #9

    Default Re: Silly question

    Dave Thomas <com> writes:
     
    >
    > It's a way of distinguishing between an instance method and a class
    > method in the doentation. When we say IO#each_byte, we're referring
    > to an instance method of class IO, whereas IO.foreach is a class
    > method.
    >
    > I personally don't like to convention too much, but I'm not sure I can
    > think of a better one.[/ref]

    I've seen Smalltalkers use this:

    MyClass >> instanceMethod

    MyClass class >> classMethod

    Jim
    --
    Jim Menard, com, http://www.io.com/~jimm/
    "An operating system is a collection of things that don't fit into a
    language. There shouldn't be one."
    -- Dan Ingalls
    Jim Guest

  10. #10

    Default Re: Silly question

    Jim Menard wrote: 

    Hey, unlike #, this can even be made executable:

    irb(main):001:0> class Class; alias >> instance_method; end
    => nil
    irb(main):002:0> String >> :reverse
    => #<UnboundMethod: String#reverse>
    irb(main):003:0> String.class >> :new
    => #<UnboundMethod: Class#new>

    I kinda like it!


    Joel Guest

Similar Threads

  1. Silly question
    By Jim Macklin in forum Macromedia Flash Flashcom
    Replies: 7
    Last Post: February 22nd, 06:36 PM
  2. silly question...
    By Wendell in forum ASP.NET Web Services
    Replies: 2
    Last Post: September 16th, 02:24 PM
  3. silly question
    By Ron in forum Sun Solaris
    Replies: 8
    Last Post: August 11th, 11:18 AM
  4. Silly question from the UK
    By garryac in forum Photography
    Replies: 15
    Last Post: July 20th, 05:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139