Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

class#method notation

0 views
Skip to first unread message

guoxi...@gmail.com

unread,
Oct 18, 2005, 4:52:13 PM10/18/05
to
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.

wannes

unread,
Oct 18, 2005, 5:02:48 PM10/18/05
to
On 18/10/05, guoxi...@gmail.com <guoxi...@gmail.com> wrote:
> 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


Kevin Ballard

unread,
Oct 18, 2005, 5:29:11 PM10/18/05
to

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

Jamis Buck

unread,
Oct 18, 2005, 5:28:08 PM10/18/05
to
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

Xiaotian Guo

unread,
Oct 18, 2005, 5:44:51 PM10/18/05
to
that makes sense, thanks!

0 new messages