3 ms·
> I can't fathom optional parenthesis. In this code it makes it very hard to know if today is an attribute or a method without knowing the context. Optional pa
by dragonwriter 4y ago
> I can't fathom optional parenthesis. In this code it makes it very hard to know if today is an attribute or a method without knowing the context.
Optional parentheses exist because it is impossible for there to be ambiguity: after a dot, if a name starts with a lowercase letter it is a method (and the reference is a call). If it starts with an upper case letter, it is constant (which is not callable as a method.) There are no other possibilities.
“Attributes” in Ruby are literally just getter methods (possibly paired with setter methods.) There is no object-dot-field access to fields (instance variables exist, but outside access to them doesn't use that syntax, but instead goes through a different set of method calls: Object#instance_variable-(get/set)