Class: Mathmas::Expression
- Inherits:
-
Object
- Object
- Mathmas::Expression
- Includes:
- Basic
- Defined in:
- lib/mathmas/core/expression.rb
Overview
Currently Mathmas have 3 types of expression, Plus, Multiply and Power. All calcs including dividing are expressed with these three.
Multiply(Number(1), Power(Plus(Symbol(x), Symbol(y), -1))
Instance Method Summary collapse
- #exec(args) ⇒ Object
-
#initialize(*args) ⇒ Expression
constructor
A new instance of Expression.
Methods included from Basic
#*, #**, #+, #-, #/, #coerce, #to_iruby
Constructor Details
#initialize(*args) ⇒ Expression
Returns a new instance of Expression.
13 14 15 |
# File 'lib/mathmas/core/expression.rb', line 13 def initialize(*args) @args = args end |
Instance Method Details
#exec(args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mathmas/core/expression.rb', line 20 def exec(args) arr = @args.map do |arg| if arg.is_a?(Variable) unless args.keys.index(arg.symbol).nil? next args[arg.symbol] else next arg end elsif arg.is_a?(Expression) next arg.exec(args) elsif arg.is_a?(Number) next arg.num else raise "Invailed Arguments" end end arr end |