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.
351 352 353 354 |
# File 'lib/sexp_processor.rb', line 351 def initialize @env = [] @env.unshift({}) end |
Instance Method Details
#[](name) ⇒ Object
TODO: depth_of
366 367 368 369 |
# File 'lib/sexp_processor.rb', line 366 def [] name hash = @env.find { |closure| closure.has_key? name } hash[name] if hash end |
#[]=(name, val) ⇒ Object
371 372 373 374 |
# File 'lib/sexp_processor.rb', line 371 def []= name, val hash = @env.find { |closure| closure.has_key? name } || current hash[name] = val end |
#all ⇒ Object
356 357 358 |
# File 'lib/sexp_processor.rb', line 356 def all @env.reverse.inject { |env, scope| env.merge scope } end |
#current ⇒ Object
376 377 378 |
# File 'lib/sexp_processor.rb', line 376 def current @env.first end |
#depth ⇒ Object
360 361 362 |
# File 'lib/sexp_processor.rb', line 360 def depth @env.length end |
#scope ⇒ Object
380 381 382 383 384 385 386 387 388 |
# File 'lib/sexp_processor.rb', line 380 def scope @env.unshift({}) begin yield ensure @env.shift raise "You went too far unextending env" if @env.empty? end end |