I believe it’s worth it to mention the generic coerce method and how the coercion might be done for generic classes. Like:
raise(ArgumentError, 'Numeric is expected') unless Numeric === number
@number = number
@number + other
The above makes it possible to use the instances of this class anywhere in the operator chain (despite Numeric#+ knows nothing about how to deal with our class instances):
3 + NumberWrapper.new(5) + 3
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.