diff options
Diffstat (limited to 'mrbgems/mruby-complex')
| -rw-r--r-- | mrbgems/mruby-complex/mrblib/complex.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/mrbgems/mruby-complex/mrblib/complex.rb b/mrbgems/mruby-complex/mrblib/complex.rb index 26a3b206f..f54151c7b 100644 --- a/mrbgems/mruby-complex/mrblib/complex.rb +++ b/mrbgems/mruby-complex/mrblib/complex.rb @@ -109,8 +109,8 @@ class Complex < Numeric alias_method :imag, :imaginary [Integer, Float].each do |cls| - [:+, :-, :*, :/, :==].each do |op| - cls.instance_eval do + cls.class_eval do + [:+, :-, :*, :/, :==].each do |op| original_operator_name = :"__original_operator_#{op}_complex" alias_method original_operator_name, op define_method op do |rhs| @@ -123,4 +123,10 @@ class Complex < Numeric end end end + Numeric.class_eval do + def i + Complex(0, self) + end + end + undef i end |
