class#method notation

G

guoxiaotian

what's the purpose of Ruby's Foo#bar notation(what's wrong with
Foo.bar)? does this mean class Foo's instance method bar or Foo's class
method bar, or both?

ri command seems support both.
 
W

wannes

what's the purpose of Ruby's Foo#bar notation(what's wrong with
Foo.bar)? does this mean class Foo's instance method bar or Foo's class
method bar, or both?

They both have different meanings:

Foo#bar : bar is an instance method of the class Foo
Foo.bar : bar is a class method of the class Foo

Hopes this helps a bit.

grtz,
wannes
 
J

Jamis Buck

In documentation, Foo#bar specifically indicates an instance method
of Foo. Foo::bar specifically indicates a class method. The problem
with the Foo.bar syntax is that it is ambiguous (in documentation),
since it can refer to either a class method or an instance method.

- Jamis
 
K

Kevin Ballard

wannes said:
They both have different meanings:

Foo#bar : bar is an instance method of the class Foo
Foo.bar : bar is a class method of the class Foo

You can also use Foo::bar to mean a class method, but that form is
traditionally used to refer to constants rather than methods.
 

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,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top