Class: RainforestRubyRuntime::Variables::Scope

Inherits:
Value
  • Object
show all
Defined in:
lib/rainforest_ruby_runtime/variables/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#call

Constructor Details

#initialize(&block) ⇒ Scope

Returns a new instance of Scope.



6
7
8
9
10
# File 'lib/rainforest_ruby_runtime/variables/scope.rb', line 6

def initialize(*, &block)
  super
  @registry = Registery.new
  instance_eval &block if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rainforest_ruby_runtime/variables/scope.rb', line 16

def method_missing(name, *args, &block)
  if @registry.has_variable?(name)
    @registry[name].call *args, &block
  else
    super
  end
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/rainforest_ruby_runtime/variables/scope.rb', line 4

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/rainforest_ruby_runtime/variables/scope.rb', line 4

def name
  @name
end

Instance Method Details

#define_variable(name, &block) ⇒ Object



12
13
14
# File 'lib/rainforest_ruby_runtime/variables/scope.rb', line 12

def define_variable(name, &block)
  @registry.register Value.new(name, &block)
end