Class: Mathmas::Number

Inherits:
Object
  • Object
show all
Includes:
Basic
Defined in:
lib/mathmas/core/number.rb

Overview

Internal use only Instantiated by Symbol#coerce or Expression#coerce

x + y is calcurated first and an instance of Expression is created. Then Fixnum#* has no rule when its argument is an instance of Expression so Expression#coerce is called. At last Expression#coerce calls Number#new.

Multiply(Number(5), Plus(Symbol(x), Symbol(y))

Examples:

5*(x + y)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Basic

#*, #**, #+, #-, #/, #coerce, #to_iruby

Constructor Details

#initialize(num) ⇒ Number

Returns a new instance of Number.



18
19
20
# File 'lib/mathmas/core/number.rb', line 18

def initialize(num)
  @num = num
end

Instance Attribute Details

#numObject

Returns the value of attribute num.



16
17
18
# File 'lib/mathmas/core/number.rb', line 16

def num
  @num
end

Instance Method Details

#to_sObject



22
23
24
# File 'lib/mathmas/core/number.rb', line 22

def to_s
  @num.to_s
end

#to_texObject



26
27
28
# File 'lib/mathmas/core/number.rb', line 26

def to_tex
  @num.to_s
end