Sha256: 4016e566d62b1610be71eb764c99ae7a3288edf22f0d9c626c8950d02ef81d9f

Contents?: true

Size: 646 Bytes

Versions: 1

Compression:

Stored size: 646 Bytes

Contents

class Environment
  attr_reader :parent, :defaults

  def initialize(parent=nil, defaults={})
    @parent = parent
    @defaults = defaults
  end

  def define(symbol, value)
    defaults[symbol] = value
  end

  def defined?(symbol)
    defaults.has_key?(symbol) || (parent && parent.defined?(symbol))
  end

  def lookup(symbol)
    defaults[symbol] || (parent && parent.lookup(symbol)) ||
      raise("#{symbol} is undefined")
  end

  def set(symbol, value)
    if defaults.has_key?(symbol)
      defaults[symbol] = value
    elsif parent.nil?
      raise("#{symbol} was undefined")
    else
      parent.set(symbol, value)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forsta-0.0.1 lib/forsta/environment.rb