Class: Kalc::Ast::Negative

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Negative

Returns a new instance of Negative.



39
40
41
# File 'lib/kalc/ast.rb', line 39

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



37
38
39
# File 'lib/kalc/ast.rb', line 37

def value
  @value
end

Instance Method Details

#eval(context) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/kalc/ast.rb', line 43

def eval(context)
  begin
    -(@value.eval(context))
  rescue
    @value.eval(context)
  end
end