Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Allow maths filters to work with objects that respond to
#to_number
as well as things that can be coerced into numbers.Why
So I can design my own complex types or Drops that can work with maths filters.
How
If an object responds to
#to_number
, it will be used byUtils.to_number
when coercing values.An example:
Now it can be used with maths filters
Notes / questions
#to_s
on the object), butUtils.to_number
, used to coerce values in maths filters, does not. I am not sure whether or not this limitation is by design / security reasons, so I'm putting this here up for discussion.#to_number
instead of a more conventional#to_i
or#to_f
to avoid accidental coercion (as many types in Ruby-land implement those) and also to mirrorUtils.to_number
. Please advice if this is not a good idea.