Newbie question about the # symbol

J

Justin

I have just started learning Ruby and I am going through as much
documentation as I can find. The only question that I cannot seem to
find an answer to concerns the use of the # symbol when referring to
methods (I think I've seen it used to refer to both class and instance
methods).

Here is an example:
http://www.rubycentral.com/book/ref_c_io.html#IO.select

On the above page there is a link to "Kernel#select" which is a class
method.

and here:
http://www.rubycentral.com/book/ref_c_object.html#Object.is_a_qm

There is a link to "Object#kind_of?" which is an instance method.
Clearly the purpose of the hash mark has another purpose. Anyone know
what document explains this?

Thanks!
Justin
 
R

rmagick

# is not Ruby syntax, it's a documentation convention that denotes
"instance method," as in "kind_of? is an instance method of Object" as
opposed to "class method," which is distinguished by a period between
the class name and the method name.
 
M

Mike Fletcher

Justin said:
There is a link to "Object#kind_of?" which is an instance method.
Clearly the purpose of the hash mark has another purpose. Anyone know
what document explains this?

The notation's explained in the preface:

http://www.rubycentral.com/book/preface.html#S10

Basically it means "the instance method kind_of? implemented by the
Object class"; not really syntax, but convention for discussing Ruby.
The 'ri' utility uses something similar.
 
J

James Edward Gray II

# is not Ruby syntax, it's a documentation convention that denotes
"instance method," as in "kind_of? is an instance method of Object" as
opposed to "class method," which is distinguished by a period between
the class name and the method name.

Class methods are also often shown as follows:

MyClass::class_method

ri even seems to favor this notation.

James Edward Gray II
 
J

Justin

Mike said:
Basically it means "the instance method kind_of? implemented by the
Object class"; not really syntax, but convention for discussing Ruby.
The 'ri' utility uses something similar.

Ahh ok, excellent thank you that was confusing me quite a bit.
 

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

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top