Class: RubyParserStuff::Environment
- Inherits:
-
Object
- Object
- RubyParserStuff::Environment
- Defined in:
- lib/ruby_parser_extras.rb
Instance Attribute Summary collapse
-
#dyn ⇒ Object
readonly
Returns the value of attribute dyn.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #all ⇒ Object
- #current ⇒ Object
- #extend(dyn = false) ⇒ Object
-
#initialize(dyn = false) ⇒ Environment
constructor
A new instance of Environment.
- #reset ⇒ Object
- #unextend ⇒ Object
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
#dyn ⇒ Object (readonly)
Returns the value of attribute dyn.
1788 1789 1790 |
# File 'lib/ruby_parser_extras.rb', line 1788 def dyn @dyn end |
#env ⇒ Object (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 |
#all ⇒ Object
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 |
#current ⇒ Object
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 |
#reset ⇒ Object
1819 1820 1821 1822 1823 |
# File 'lib/ruby_parser_extras.rb', line 1819 def reset @dyn.clear @env.clear self.extend end |
#unextend ⇒ Object
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 |