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
- #depth ⇒ Object
-
#initialize ⇒ Environment
constructor
A new instance of Environment.
- #scope ⇒ Object
Constructor Details
#initialize ⇒ Environment
Returns a new instance of Environment.
337 338 339 340 |
# File 'lib/sexp_processor.rb', line 337 def initialize @env = [] @env.unshift({}) end |
Instance Method Details
#[](name) ⇒ Object
TODO: depth_of
352 353 354 355 |
# File 'lib/sexp_processor.rb', line 352 def [] name hash = @env.find { |closure| closure.has_key? name } hash[name] if hash end |
#[]=(name, val) ⇒ Object
357 358 359 360 |
# File 'lib/sexp_processor.rb', line 357 def []= name, val hash = @env.find { |closure| closure.has_key? name } || @env.first hash[name] = val end |
#all ⇒ Object
342 343 344 |
# File 'lib/sexp_processor.rb', line 342 def all @env.reverse.inject { |env, scope| env.merge scope } end |
#depth ⇒ Object
346 347 348 |
# File 'lib/sexp_processor.rb', line 346 def depth @env.length end |
#scope ⇒ Object
362 363 364 365 366 367 368 369 370 |
# File 'lib/sexp_processor.rb', line 362 def scope @env.unshift({}) begin yield ensure @env.shift raise "You went too far unextending env" if @env.empty? end end |