From: Robin Date: 2007-05-10T04:35:17+09:00 Subject: Re: Use of Double-Colon :: On 9 May, 20:15, dbl...@wobblini.net wrote: > Hi -- > > > > On Thu, 10 May 2007, robni...@gmail.com wrote: > > Hi, > > > I'm new to Ruby and throughly enjoying learning the language. I'm > > currently working my way through the Pickaxe book, but have a couple > > of questions I hope someone can help me out with. > > > As I understand it the double-colon ( :: ) can be used when calling > > class methods or class constants, but could correctly be replaced by a > > single dot ( . ) if preferred: > > > SongList::is_too_long(song1) > > SongList.is_too_long(song1) > > > I was wondering if someone more experience could tell me which method > > is used by the majority of Rubyists and whether it is thought of as > > "best practice" to use the double colon? > > > I suspect this is probably down to personal preference. I personally > > prefer the double-colon but I would like to get into good habits now > > whilst I'm learning the language. The Pickaxe book doesn't use :: > > except when referring to modules (not sure if that is the correct > > term), e.g., > > > class TestRoman < Test::Unit::TestCase > > #... > > end > > > Could someone explain whether this is convention or if there is > > another reason for this? > > I think it's clearer just to use a dot to mean "send this to the > object", and :: to drill down constant scope. I don't think there's > any reason to use a different operator just because the receiver is a > class or module. You're still doing the same thing: sending a message > to an object. So I'd just use the dot. > > David > > -- > Q. What is THE Ruby book for Rails developers? > A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) > (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) > Q. Where can I get Ruby/Rails on-site training, consulting, coaching? > A. Ruby Power and Light, LLC (http://www.rubypal.com) Thanks everyone. That all makes sense. I first met double-colon in the Class methods section of "why's guide to ruby" ( http://poignantguide.net/ruby/chapter-3.html ), it doesn't mention using dot as an alternative in that section so I assumed double-colon was the standard. Thanks for clearing it up. Robin