3 ms·
It all stems from that `+` in Ruby is not something mathematical. It is merely a method that needs to be defined on the expression that it follows: Time.no
by cies 11y ago
It all stems from that `+` in Ruby is not something mathematical. It is merely a method that needs to be defined on the expression that it follows:
Time.now.+(1.month).+(5.days)
Or:
Time.now.send(:"+", 1.month).send(:"+", 5.days)
`Time.now` evaluates to an object of the class `Time`, which implements the method `+`.
If you are looking for a language basis itself more on "laws" then on "message passing", I found this is Haskell.
In Haskell `+` is a function that need to be implemented for all types in the `Num` type-class. `+` can only add two `Num`s of the same type (and evaluates to a value of that specific type), thus explicit conversion is needed. See the docs here:
http://hackage.haskell.org/package/base-4.8.0.0/docs/Prelude.html#v:-43- http://hackage.haskell.org/package/base-4.8.0.0/docs/Prelude...