3 ms·
> If I've got that right You did. > it sounds functionally similar to the Python way It definitely is, however it allows to handle all operators by defining
by byroot 6y ago
> If I've got that right
You did.
> it sounds functionally similar to the Python way
It definitely is, however it allows to handle all operators by defining a single method, so it's a bit more usable.
> does the coerce thing automatically happen for any type, or is that special behavior implemented by Ruby's Number types?
Only for number types. For other core types using binary operators, you have dedicated implicit conversion methods. For instance `"foo" + MyType.new` will try to call `MyType.new.to_str`.
`to_str` being specifically for implicit conversions, and `to_s` for explicit conversions. So implicit conversions won't happen unless specifically defined.
- xscott 6y agoThis approach seems nice in that it fast-tracks the common case and only delegates if needed. > it allows to handle all operators by defining a single method, That's nice and pragmatic too. Back to the subject of this submission, I suspect the coerce idea could be bolted onto Wren without really breaking or changing much of anything (just an additional branch in the error handling of Wren's builtin Num type). That would allow Wren to grow it's own numpy-like library someday.