Class: BlockNode
- Inherits:
-
Object
- Object
- BlockNode
- Defined in:
- lib/nodes.rb
Overview
Class for statements to be evaluated as a code-block.
Instance Method Summary collapse
-
#evaluate(scope) ⇒ Object
Evaluate block based on scope.
-
#initialize(statements = nil) ⇒ BlockNode
constructor
A new instance of BlockNode.
Constructor Details
#initialize(statements = nil) ⇒ BlockNode
Returns a new instance of BlockNode.
88 89 90 |
# File 'lib/nodes.rb', line 88 def initialize(statements = nil) @block = statements end |
Instance Method Details
#evaluate(scope) ⇒ Object
Evaluate block based on scope.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/nodes.rb', line 93 def evaluate(scope) return nil unless @block result = nil @block.each do |statement| result = statement.evaluate(scope) # Returns the result if the value is a return value. Needed for returns in nestled blocks. return result if result.is_a?(ReturnValue) end return result end |