Class: Brakeman::SexpProcessor::Environment
- Defined in:
- lib/ruby_parser/bm_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
-
#[](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.
156 157 158 159 |
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 156 def initialize @env = [] @env.unshift({}) end |
Instance Method Details
#[](name) ⇒ Object
TODO: depth_of
171 172 173 174 |
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 171 def [] name hash = @env.find { |closure| closure.has_key? name } hash[name] if hash end |
#[]=(name, val) ⇒ Object
176 177 178 179 |
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 176 def []= name, val hash = @env.find { |closure| closure.has_key? name } || @env.first hash[name] = val end |
#all ⇒ Object
161 162 163 |
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 161 def all @env.reverse.inject { |env, scope| env.merge scope } end |
#depth ⇒ Object
165 166 167 |
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 165 def depth @env.length end |
#scope ⇒ Object
181 182 183 184 185 186 187 188 189 |
# File 'lib/ruby_parser/bm_sexp_processor.rb', line 181 def scope @env.unshift({}) begin yield ensure @env.shift raise "You went too far unextending env" if @env.empty? end end |