why "::", not "."

O

Oleg Igor

Why does the method of modules use a dot, and the constants a double
colon?
e.g.
Math::pI and Math.cos
 
R

Ryan Davis

Why does the method of modules use a dot, and the constants a double
colon?
e.g.
Math::pI and Math.cos

For the same reason why inner-classes/modules use double colon, because =
they're constants and that's how you look up via constant namespace.

Math::pI and ActiveRecord::Base are the same type of lookup... it is =
just that Base is a module and PI is a float.

You can also use double-colon for invocation:

% ruby -e 'p Math::exp(1)'
2.71828182845905

but that is frowned upon as non-idiomatic ruby.
 
R

Rick DeNatale

You can also use double-colon for invocation:

% ruby -e 'p Math::exp(1)'
2.71828182845905

but that is frowned upon as non-idiomatic ruby.

Not so much non-idiomatic as archaic.

Kind of like using thee and thou, or goeth (as in "Pride goeth before
the fall") in modern English. <G>


--
Rick DeNatale

Help fund my talk at Ruby Conf 2010:http://pledgie.com/campaigns/13677
Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 

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,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top