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…
Get name
from env at whatever scope it is defined in, or
return nil.
# File lib/sexp_processor.rb, line 424 def [] name hash = @env.find { |closure| closure.key? name } hash[name] if hash end
If name
exists in the env, set it to val
in
whatever scope it is in. If it doesn't exist, set name
to
val
in the current scope.
# File lib/sexp_processor.rb, line 434 def []= name, val hash = @env.find { |closure| closure.key? name } || current hash[name] = val end
Flatten out all scopes and return all key/value pairs.
# File lib/sexp_processor.rb, line 408 def all @env.reverse.inject { |env, scope| env.merge scope } end
Get the current/top environment.
# File lib/sexp_processor.rb, line 442 def current @env.first end
Return the current number of scopes.
# File lib/sexp_processor.rb, line 415 def depth @env.length end
Create a new scope and yield to the block passed.
# File lib/sexp_processor.rb, line 449 def scope @env.unshift({}) begin yield ensure @env.shift raise "You went too far unextending env" if @env.empty? end end