3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/sqrt/times.rb', line 3
def included(klass)
Integer.class_eval do
alias_method :math_times, :*
def *(x)
x.class == Sqrt::Object ? Sqrt::Object.new(self.math_times(x.instance_variable_get(:@coefficient)), x.instance_variable_get(:@value)) : self.math_times(x)
end
end
Float.class_eval do
alias_method :math_times, :*
def *(x)
x.class == Sqrt::Object ? Sqrt::Object.new(self.math_times(x.instance_variable_get(:@coefficient)), x.instance_variable_get(:@value)) : self.math_times(x)
end
end
Rational.class_eval do
alias_method :math_times, :*
def *(x)
x.class == Sqrt::Object ? Sqrt::Object.new(self.math_times(x.instance_variable_get(:@coefficient)), x.instance_variable_get(:@value)) : self.math_times(x)
end
end
Complex.class_eval do
alias_method :math_times, :*
def *(x)
x.class == Sqrt::Object ? Sqrt::Object.new(self.math_times(x.instance_variable_get(:@coefficient)), x.instance_variable_get(:@value)) : self.math_times(x)
end
end
end
|