Class: SexpProcessor::Environment
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
-
#[](name) ⇒ Object
TODO: depth_of.
- #[]=(name, val) ⇒ Object
- #all ⇒ Object
- #current ⇒ Object
- #depth ⇒ Object
-
#initialize ⇒ Environment
constructor
A new instance of Environment.
- #scope ⇒ Object
Constructor Details
#initialize ⇒ Environment
Returns a new instance of Environment.
384 385 386 387 |
# File 'lib/sexp_processor.rb', line 384 def initialize @env = [] @env.unshift({}) end |
Instance Method Details
#[](name) ⇒ Object
TODO: depth_of
399 400 401 402 |
# File 'lib/sexp_processor.rb', line 399 def [] name hash = @env.find { |closure| closure.has_key? name } hash[name] if hash end |
#[]=(name, val) ⇒ Object
404 405 406 407 |
# File 'lib/sexp_processor.rb', line 404 def []= name, val hash = @env.find { |closure| closure.has_key? name } || current hash[name] = val end |
#all ⇒ Object
389 390 391 |
# File 'lib/sexp_processor.rb', line 389 def all @env.reverse.inject { |env, scope| env.merge scope } end |
#current ⇒ Object
409 410 411 |
# File 'lib/sexp_processor.rb', line 409 def current @env.first end |
#depth ⇒ Object
393 394 395 |
# File 'lib/sexp_processor.rb', line 393 def depth @env.length end |
#scope ⇒ Object
413 414 415 416 417 418 419 420 421 |
# File 'lib/sexp_processor.rb', line 413 def scope @env.unshift({}) begin yield ensure @env.shift raise "You went too far unextending env" if @env.empty? end end |