I am relatively new to Ruby and find it confusing that the following pairs of examples work equally well:
File.included_modules
File::included_modules
File.stat('mbox') # Returns a '#<File::Stat..>' object
File::stat('mbox')
File.new("foo.txt", "w")
File::new("foo.txt", "w")
"asdf".size # An instance method
"asdf"::size
2 + 3
2::send(:+, 3) # An extreme example
File::new
, in particular, is something I quite frequently encounter.
My question: Would it be non-idiomatic for me to avoid ever using the :: operator for qualifying the names of anything but classes, modules, and constants and, instead, consistently to use only dot syntax for all methods (class methods, module methods, and instance methods)?
To be clear: are there any situations in which I would want to refer to a method (whether in code or in documentation) using anything other than dot syntax?
Sources consulted:
- 2007: https://www.ruby-forum.com/topic/107527
- 2010: What is Ruby's double-colon `::`?
- 2010: What does ::MyClass Ruby scope operator do?
- 2010: https://www.ruby-forum.com/topic/315853
- 2011: Double colons before class names in Ruby?
- 2012: Ruby's double colon (::) operator usage differences
- 2014: Ruby class naming convention with double colon
- http://www.tutorialspoint.com/ruby/ruby_operators.htm