Class: SexpProcessor::Environment

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

Overview

I really hate this here, but I hate subdirs in my lib dir more… I guess it is kinda like shaving… I’ll split this out when it itches too much…

Instance Method Summary collapse

Constructor Details

#initializeEnvironment

Returns a new instance of Environment.



332
333
334
335
# File 'lib/sexp_processor.rb', line 332

def initialize
  @env = []
  @env.unshift({})
end

Instance Method Details

#[](name) ⇒ Object

TODO: depth_of



347
348
349
350
# File 'lib/sexp_processor.rb', line 347

def [] name
  hash = @env.find { |closure| closure.has_key? name }
  hash[name] if hash
end

#[]=(name, val) ⇒ Object



352
353
354
355
# File 'lib/sexp_processor.rb', line 352

def []= name, val
  hash = @env.find { |closure| closure.has_key? name } || @env.first
  hash[name] = val
end

#allObject



337
338
339
# File 'lib/sexp_processor.rb', line 337

def all
  @env.reverse.inject { |env, scope| env.merge scope }
end

#depthObject



341
342
343
# File 'lib/sexp_processor.rb', line 341

def depth
  @env.length
end

#scopeObject



357
358
359
360
361
362
363
364
365
# File 'lib/sexp_processor.rb', line 357

def scope
  @env.unshift({})
  begin
    yield
  ensure
    @env.shift
    raise "You went too far unextending env" if @env.empty?
  end
end