Class: RubyParserStuff::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_parser_extras.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dyn = false) ⇒ Environment

Returns a new instance of Environment.



1813
1814
1815
1816
1817
# File 'lib/ruby_parser_extras.rb', line 1813

def initialize dyn = false
  @dyn = []
  @env = []
  self.reset
end

Instance Attribute Details

#dynObject (readonly)

Returns the value of attribute dyn.



1788
1789
1790
# File 'lib/ruby_parser_extras.rb', line 1788

def dyn
  @dyn
end

#envObject (readonly)

Returns the value of attribute env.



1788
1789
1790
# File 'lib/ruby_parser_extras.rb', line 1788

def env
  @env
end

Instance Method Details

#[](k) ⇒ Object



1790
1791
1792
# File 'lib/ruby_parser_extras.rb', line 1790

def [] k
  self.all[k]
end

#[]=(k, v) ⇒ Object



1794
1795
1796
1797
# File 'lib/ruby_parser_extras.rb', line 1794

def []= k, v
  raise "no" if v == true
  self.current[k] = v
end

#allObject



1799
1800
1801
1802
# File 'lib/ruby_parser_extras.rb', line 1799

def all
  idx = @dyn.index(false) || 0
  @env[0..idx].reverse.inject { |env, scope| env.merge scope }
end

#currentObject



1804
1805
1806
# File 'lib/ruby_parser_extras.rb', line 1804

def current
  @env.first
end

#extend(dyn = false) ⇒ Object



1808
1809
1810
1811
# File 'lib/ruby_parser_extras.rb', line 1808

def extend dyn = false
  @dyn.unshift dyn
  @env.unshift({})
end

#resetObject



1819
1820
1821
1822
1823
# File 'lib/ruby_parser_extras.rb', line 1819

def reset
  @dyn.clear
  @env.clear
  self.extend
end

#unextendObject



1825
1826
1827
1828
1829
# File 'lib/ruby_parser_extras.rb', line 1825

def unextend
  @dyn.shift
  @env.shift
  raise "You went too far unextending env" if @env.empty?
end