Is this old style Ruby?

P

Paul van Tilburg

Florian Gross said:
And you can not use :: for accessing methods that start with an
uppercase letter:

That's not exactly true:

[...]

If you supply a parameter list (or even empty parentheses), ruby will use
:: for accessing methods with an uppercase letter, otherwise it will
assume you are trying to access a constant.

That's exactly why I use . for both class and instance method-calls
and :: for constants, there still is this overlap but a better
semantical devision. Since :: gives a feel for working with
"namespaces" (Foo::Bar, Foo::Bar::Konstant) and class and module names are
constants too. The . is well-known for method calls (regardless the tape)
and you also don't do: def MyClass::classmethod; ... ; end.

That's the guideline I follow at least, just my 2¢.
It seems to be clearer for RubyNubies too (in my experience explaining
instance methods, class methods and namespaces to them).

Paul
[/QUOTE]
 
Y

YANAGAWA Kazuhisa

In Message-Id: <[email protected]>
It seems a little bit odd to me to have two ways of doing the same
thing. Seems best (as was mentioned above) to stick to :: for module
access and . for everything else. ??

For consistency use ".", for uniformity with other languages use
"::". Historically Foo::foo() notation was introduced for those who
said that could be more understandable for C++ or Java people.

For my own preference, I use "." since that consistent in Ruby ---
in Foo.foo, receiver is Foo itself --- and "::" notation always needs
() if method name is capitalized.

# Well, capitalized name of class methods also out of my preference....
class Foo; def self.foo; p :foo; end; end
Foo.foo
Foo::foo
:foo
:foo
class Foo; def self.Bar; p :bar; end; end
Foo.Bar
Foo::Bar
:bar
-:3: uninitialized constant Foo::Bar (NameError)
 
H

Hal Fulton

David said:
Hi --




I've never seen :: used where the receiver was anything but a Class or
Module, and usually for constant access rather than method access.
*Please* let's not start seeing it in the general case....

Some people do it -- I've seen it before, but I don't advocate it.
It smells like C++ to me.
I would advocate :: for constant access, and . for method access.

I also advocate . for methods.

:: is necessary for constants. (I once started a thread where I wondered
why we couldn't use dot for constants -- but eventually I painted myself
into a corner and realized "it's already done the right way.")


Hal
 
H

Hal Fulton

So you would say use :: only for constant access, and use '.' for
method access be it in a class or module?

Certainly, IMO. I usually say Math.sin rather than Math::sin. Basically
I don't care in general whether it's a class or just a module. (There
might be times when I do care.)

As for module names and class names (replying to what someone else said),
remember that these are typically constants. In other words, if Foo::Bar
is a class, it's just a special case of Foo::Bar being a constant.


Hal
 
Y

Yukihiro Matsumoto

Hi

In message "Re: Is this old style Ruby?"
on Wed, 16 Feb 2005 00:54:53 +0900, (e-mail address removed) writes:

|Oh now I'm confused....
|
|Where's Matz??? :eek:)

Here I am. ;-)

I allow '::' for method calls to denote class methods (with C++ style
appearance). David doesn't like it. I think _why liked it.

matz.
 
B

Bertram Scharpf

Hi,

Am Dienstag, 15. Feb 2005, 22:54:54 +0900 schrieb (e-mail address removed):
In Why's guide, I see the line:

File::eek:pen( ...etc.

Up 'til now I've always written this as:

File.open( ...etc.

(ie. using a . rather than a ::). Am I right in thinking the :: for
accessing class methods is now old-style?

`::' may be used to qualify top-level constants:

X=1 ; class C ; X=2 ; def C.f ; ::X ; end ; end ; C.f
# => 1

You can't do that with `.'.

Bertram
 
D

David A. Black

Hi --

Hi

In message "Re: Is this old style Ruby?"
on Wed, 16 Feb 2005 00:54:53 +0900, (e-mail address removed) writes:

|Oh now I'm confused....
|
|Where's Matz??? :eek:)

Here I am. ;-)

I allow '::' for method calls to denote class methods (with C++ style
appearance). David doesn't like it. I think _why liked it.

I never learned C++, so I can't experience the pleasure of being
reminded of its style :)


David
 
J

Jim Weirich

I never learned C++, so I can't experience the pleasure of being
reminded of its style :)

I, however, am very familiar with C++, and I also cannot experience the
pleasure of being reminded of its style. ;)
 
W

why the lucky stiff

Yukihiro said:
I allow '::' for method calls to denote class methods (with C++ style
appearance). David doesn't like it. I think _why liked it.

I like it okay. Not with fervor.

@var is instance var. obj.meth is instance method.
@@var is class var. obj::meth is class method.

I guess I thought that the notion of single-character for any instance
syntax and double-character for any class syntax might be simpler.

It's arbitrary, though. If it's confusing to most, I definitely want to
change it's use in the (Poignant) Guide.

_why
 
F

Florian Gross

why said:
I like it okay. Not with fervor.

@var is instance var. obj.meth is instance method.
@@var is class var. obj::meth is class method.

I guess I thought that the notion of single-character for any instance
syntax and double-character for any class syntax might be simpler.

With such cases (I apply the same rule to constant naming, I don't see
why I should use SHOUTING_CAPS for non-class constants) I always wonder
about others doing an arbitrary distinction between classes and objects
-- are classes after all not also objects?
 

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,169
Messages
2,570,915
Members
47,456
Latest member
JavierWalp

Latest Threads

Top