3 ms·
It's not just 'anything' that objects are extended with in Ruby, they are extended with suitable methods pertaining to the domain at hand. 'seconds' is a conver
by tinco 9y ago
It's not just 'anything' that objects are extended with in Ruby, they are extended with suitable methods pertaining to the domain at hand. 'seconds' is a conversion method of one type into another. You might as well ask why do objects have a 'toString' method. Because it is convenient.
- kureikain 9y agoThank you for explaining this.
- pavlov 9y agoWhy does one conversion method have the “to” prefix and the other doesn’t? I guess because the inconsistency looks somehow prettier. But this is what drives me up the wall with the Ruby ecosystem: seems that whenever API designers had the choice between consistency and fun gimmick, they chose the latter. It makes some people feel happy, but often makes the next person who has to read and maintain the code miserable.
- jashmatthews 9y ago10.seconds is not part of the Ruby stdlib. It's Rails ActiveSupport. That's why it's different.