Silly question

B

Brad

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


Regards,
Brad
 
D

Dan Doel

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
 
G

Gavin Sinclair

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



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
 
B

Brad

Dan said:
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. :)

Thanks,
Brad
 
B

Brad

Gavin said:
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. :)

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
 
D

Dave Thomas

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
 
D

Dave Thomas

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


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

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--
 
B

Brad

Dave said:
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
 
J

Jim Menard

Dave Thomas said:
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
 
J

Joel VanderWerf

Jim said:
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top