Class: Kalc::Ast::Identifier

Inherits:
Object
  • Object
show all
Defined in:
lib/kalc/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, value) ⇒ Identifier

Returns a new instance of Identifier.



204
205
206
207
# File 'lib/kalc/ast.rb', line 204

def initialize(identifier, value)
  @variable = identifier.to_s.strip
  @value = value
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



201
202
203
# File 'lib/kalc/ast.rb', line 201

def identifier
  @identifier
end

#valueObject (readonly)

Returns the value of attribute value.



202
203
204
# File 'lib/kalc/ast.rb', line 202

def value
  @value
end

Instance Method Details

#eval(context) ⇒ Object



209
210
211
# File 'lib/kalc/ast.rb', line 209

def eval(context)
  context.add_variable(@variable, @value.eval(context))
end