module Mathmas::Basic
Public Instance Methods
*(arg)
click to toggle source
# File lib/mathmas/core/basic.rb, line 14 def *(arg) arg = (arg.is_a?(Numeric) ? Number.new(arg) : arg) Multiply.new(self, arg) end
**(arg)
click to toggle source
# File lib/mathmas/core/basic.rb, line 28 def **(arg) arg = (arg.is_a?(Numeric) ? Number.new(arg) : arg) Power.new(self, arg) end
+(arg)
click to toggle source
TODO: delete the line arg=( ? : )
# File lib/mathmas/core/basic.rb, line 4 def +(arg) arg = (arg.is_a?(Numeric) ? Number.new(arg) : arg) Plus.new(self, arg) end
-(arg)
click to toggle source
# File lib/mathmas/core/basic.rb, line 9 def -(arg) arg = (arg.is_a?(Numeric) ? Number.new(arg) : arg) Plus.new(self, Multiply.new(Number.new(-1), arg)) end
/(arg)
click to toggle source
# File lib/mathmas/core/basic.rb, line 19 def /(arg) arg = (arg.is_a?(Numeric) ? Number.new(arg) : arg) if self.is_a?(Number) && self.num == 1 Power.new(arg, Number.new(-1)) else Multiply.new(self, Power.new(arg, Number.new(-1))) end end
coerce(other)
click to toggle source
# File lib/mathmas/core/basic.rb, line 33 def coerce(other) if other.is_a? Numeric return Mathmas::Number.new(other), self else raise "There is no rule for handling #{other.to_s}." end end
to_iruby()
click to toggle source
# File lib/mathmas/core/basic.rb, line 41 def to_iruby # Dirty Hack for IRuby. I hope IRuby will fix the problem in the future. # ["text/latex", self.to_tex] not work. html = "<script type=\"math/tex; mode=display\">#{ self.to_tex }</script>" ['text/html', html] end