Class: Fusion::Env

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

Overview

Environment: maps names -> values, with a parent chain. Built-ins live at root.

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ Env

Returns a new instance of Env.



581
582
583
584
# File 'lib/fusion.rb', line 581

def initialize(parent = nil)
  @vars = {}
  @parent = parent
end

Instance Method Details

#child(bindings = {}) ⇒ Object



601
602
603
604
605
# File 'lib/fusion.rb', line 601

def child(bindings = {})
  e = Env.new(self)
  bindings.each { |k, v| e.define(k, v) }
  e
end

#define(name, value) ⇒ Object



586
587
588
589
# File 'lib/fusion.rb', line 586

def define(name, value)
  @vars[name] = value
  self
end

#lookup(name) ⇒ Object



591
592
593
594
595
596
597
598
599
# File 'lib/fusion.rb', line 591

def lookup(name)
  if @vars.key?(name)
    @vars[name]
  elsif @parent
    @parent.lookup(name)
  else
    :__unbound__
  end
end