When I see any Ruby method printed in text, it usually appears as:
Class#method or
#method Now, I would use:
Class.method Why are all Ruby methods preceded by a pound sign? Is there any reason for it?
Use :: for describing class methods, # for describing instance methods, and use . for example code.
The "#{}" syntax is called 'interpolation' and the pound was picked most likely because interpolation is similar in a sense to commenting, because you are changing the context of your code (in this case to another context for execution)
Note that the convention is:
Class#method rather than
object#method In code you would have object.method, if object was an instance of class. The # convention is not used in code.
From the RDoc documentation:
Use :: for describing class methods, # for describing instance methods, and use . for example code.
The # notation is used to refer to the canonical instance method, like String#upcase. The . notation is used to refer to the method of a particular instance, like mystring.upcase. The distinction is made to not imply that a class method 'upcase' exists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With