4 ms·
In Ruby, methods called mainly for side effects rather than return value conventionally return the object itself, and so can be chanined by: an_object.a_meth
by dragonwriter 1y ago
In Ruby, methods called mainly for side effects rather than return value conventionally return the object itself, and so can be chanined by:
an_object.a_method.another_method
but, sure, it's less elegant (or at least less terse) than Smalltalk for the specific case of chaining invocations of methods with meaningful return values which are called for their side effects while discarding the return values.
- dominicrose 1y agoI guess it's OK if the convention is well respected. It's the case in the jQuery library for example. But yes it's a bit terse in Ruby because the default value is the last statement so it's known and predictable only if you look at the code paths. I would feel more confortable doing this if the IDE checks that it's OK.