Avoid making top-level `env` in initialization code; ref #4581

parent 0b5e1550
......@@ -104,18 +104,18 @@ class Complex < Numeric
end
alias_method :imag, :imaginary
end
[Fixnum, Float].each do |cls|
[:+, :-, :*, :/, :==].each do |op|
cls.instance_exec do
original_operator_name = "__original_operator_#{op}_complex"
alias_method original_operator_name, op
define_method op do |rhs|
if rhs.is_a? Complex
Complex(self).send(op, rhs)
else
send(original_operator_name, rhs)
[Fixnum, Float].each do |cls|
[:+, :-, :*, :/, :==].each do |op|
cls.instance_exec do
original_operator_name = "__original_operator_#{op}_complex"
alias_method original_operator_name, op
define_method op do |rhs|
if rhs.is_a? Complex
Complex(self).send(op, rhs)
else
send(original_operator_name, rhs)
end
end
end
end
......
......@@ -89,28 +89,29 @@ module Kernel
a, b = b, a % b until b == 0
Rational._new(numerator.div(a), denominator.div(a))
end
end
[:+, :-, :*, :/, :<=>, :==, :<, :<=, :>, :>=].each do |op|
Fixnum.instance_eval do
original_operator_name = "__original_operator_#{op}_rational"
alias_method original_operator_name, op
define_method op do |rhs|
if rhs.is_a? Rational
Rational(self).__send__(op, rhs)
else
__send__(original_operator_name, rhs)
[:+, :-, :*, :/, :<=>, :==, :<, :<=, :>, :>=].each do |op|
Fixnum.instance_eval do
original_operator_name = "__original_operator_#{op}_rational"
alias_method original_operator_name, op
define_method op do |rhs|
if rhs.is_a? Rational
Rational(self).__send__(op, rhs)
else
__send__(original_operator_name, rhs)
end
end
end
end
Float.instance_eval do
original_operator_name = "__original_operator_#{op}_rational"
alias_method original_operator_name, op
define_method op do |rhs|
if rhs.is_a? Rational
rhs = rhs.to_f
Float.instance_eval do
original_operator_name = "__original_operator_#{op}_rational"
alias_method original_operator_name, op
define_method op do |rhs|
if rhs.is_a? Rational
rhs = rhs.to_f
end
__send__(original_operator_name, rhs)
end
__send__(original_operator_name, rhs)
end
end if Object.const_defined?(:Float)
end if Object.const_defined?(:Float)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment