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 documentation.

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. :slight_smile:

Regards,
Brad

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

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 documentation convention only; the language does not
recognise it.

Cheers,
Gavin

···

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

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 documentation.

It’s a way of distinguishing between an instance method and a class
method in the documentation. 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

···

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

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 documentation.

Hi –

···

On Mon, 2 Feb 2004, Dan Doel wrote:

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.

It is :slight_smile:

David


David A. Black
dblack@wobblini.net

Dan Doel wrote:

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:

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

Thanks,
Brad

Gavin Sinclair wrote:

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 documentation.

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 documentation convention only; the language does not
recognise it.

Cheers,
Gavin

Gavin:

Hey thanks for the reply! I kind of figured that the use of ‘#’ between
a class and a method was only a documentation 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. :slight_smile:

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

···

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

Dave Thomas dave@pragprog.com writes:

···

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

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 documentation.

It’s a way of distinguishing between an instance method and a class
method in the documentation. 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.

I’ve seen Smalltalkers use this:

MyClass >> instanceMethod

MyClass class >> classMethod

Jim

Jim Menard, jimm@io.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

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

···

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

Hey thanks for the reply! I kind of figured that the use of ‘#’
between
a class and a method was only a documentation 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. :slight_smile:

Jim Menard wrote:

I’ve seen Smalltalkers use this:

MyClass >> instanceMethod

MyClass class >> classMethod

Jim

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!

Dave Thomas wrote:

Hey thanks for the reply! I kind of figured that the use of ‘#’
between
a class and a method was only a documentation 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. :slight_smile:

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

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

···

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