Class: Kalc::Ast::Variable
- Inherits:
-
Object
- Object
- Kalc::Ast::Variable
- Defined in:
- lib/kalc/ast.rb
Instance Attribute Summary collapse
-
#variable ⇒ Object
readonly
Returns the value of attribute variable.
Instance Method Summary collapse
- #eval(context) ⇒ Object
-
#initialize(variable) ⇒ Variable
constructor
A new instance of Variable.
Constructor Details
#initialize(variable) ⇒ Variable
Returns a new instance of Variable.
215 216 217 |
# File 'lib/kalc/ast.rb', line 215 def initialize(variable) @variable = variable end |
Instance Attribute Details
#variable ⇒ Object (readonly)
Returns the value of attribute variable.
213 214 215 |
# File 'lib/kalc/ast.rb', line 213 def variable @variable end |
Instance Method Details
#eval(context) ⇒ Object
219 220 221 222 223 |
# File 'lib/kalc/ast.rb', line 219 def eval(context) var = context.get_variable(@variable) fail "Invalid variable: #{@variable}" unless var var.class == BigDecimal ? var : var.eval(context) end |