Class: Code::Node::Negation
- Inherits:
-
Code::Node
- Object
- Code::Node
- Code::Node::Negation
- Defined in:
- lib/code/node/negation.rb
Constant Summary collapse
- EXCLAMATION_POINT =
"!"- PLUS =
"+"
Instance Method Summary collapse
- #evaluate(**args) ⇒ Object
-
#initialize(negation) ⇒ Negation
constructor
A new instance of Negation.
Constructor Details
#initialize(negation) ⇒ Negation
Returns a new instance of Negation.
7 8 9 10 |
# File 'lib/code/node/negation.rb', line 7 def initialize(negation) @operator = negation.fetch(:operator) @statement = ::Code::Node::Statement.new(negation.fetch(:statement)) end |
Instance Method Details
#evaluate(**args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/code/node/negation.rb', line 12 def evaluate(**args) object = @statement.evaluate(**args) if operator == EXCLAMATION_POINT if object.truthy? ::Code::Object::Boolean.new(false) else ::Code::Object::Boolean.new(true) end elsif operator == PLUS object else raise NotImplementedError.new(operator) end end |