New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Module.prepend instead of alias_method and unify behavior of all Numeric extensions #20038
Conversation
Build is passing - not sure why travis is reporting it's still building. |
Looks good 👍 On Wednesday, May 6, 2015, Bernard Potocki notifications@github.com wrote:
|
We can't change this too easily because there aliases are public API. We could deprecate them but I'm not sure if we will have any improvement on doing so. |
Oops, I should not have closed. |
I think those methods only existed due to the alias method chain stuff, so I'd be game to deprecating them now that we can use prepend. Extremely low priority thing to do, though. On another topic, it freaks me out moving code like that because of indent =(, I wonder if declaring the modules as |
…ad of alias_method
@carlosantoniodasilva removed indentation, added deprecated |
|
||
[Fixnum, Bignum, Float, BigDecimal].each do |klass| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't this just be Numeric.prepend
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be delighted to do so, but we've never overwritten Complex
and Rational
so I hesitated a little:
>> ObjectSpace.each_object(Class).select { |klass| klass < Numeric }
#=> [Complex, Rational, Bignum, Float, Fixnum, Integer]
and it looks like it will not work properly:
>> ActiveSupport::NumberHelper.number_to_percentage Complex(2,2)
#=> RangeError: can't convert 2+2i into Float
Use Module.prepend instead of alias_method and unify behavior of all Numeric extensions
This seems like a fine improvement from the implementation side. If we're ever going to deprecate the aliases which were really only there for implementation reasons, Rails 5 is the version to do it. |
We use one period after spaces, not two.
This is a follow-up pull request to #19434 - now that Ruby 2.2.2 is out we can switch to #prepend.
/cc @rafaelfranca @kirs