Forum: Ruby Newbie question about the # symbol

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
280577cc02ad50d7776afde4d852b22b?d=identicon&s=25 Justin (Guest)
on 2006-03-14 14:20
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#...

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
B33ea5c12d767bfd1253940a960274f5?d=identicon&s=25 rmagick@gmail.com (Guest)
on 2006-03-14 14:34
(Received via mailing list)
# 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.
357558a6682f4d6624594763d9acdb35?d=identicon&s=25 Mike Fletcher (fletch)
on 2006-03-14 14:35
Justin wrote:

> 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.
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-03-14 14:45
(Received via mailing list)
On Mar 14, 2006, at 7:33 AM, rmagick@gmail.com wrote:

> # 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
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-03-14 14:45
(Received via mailing list)
On Mar 14, 2006, at 7:20 AM, Justin wrote:

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

Actually, all the Kernel methods are instance methods, so they can be
mixed into Object.

James Edward Gray II
280577cc02ad50d7776afde4d852b22b?d=identicon&s=25 Justin (Guest)
on 2006-03-14 14:46
Mike Fletcher wrote:
> 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.
This topic is locked and can not be replied to.