Class: RubyParserStuff::Environment
- Defined in:
- lib/ruby_parser/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
- #dynamic ⇒ Object
- #dynamic? ⇒ Boolean
- #extend(dyn = false) ⇒ Object
-
#initialize(dyn = false) ⇒ Environment
constructor
A new instance of Environment.
- #reset ⇒ Object
- #unextend ⇒ Object
- #use(id) ⇒ Object
- #used?(id) ⇒ Boolean
Constructor Details
#initialize(dyn = false) ⇒ Environment
Returns a new instance of Environment.
958 959 960 961 962 963 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 958 def initialize dyn = false @dyn = [] @env = [] @use = [] self.reset end |
Instance Attribute Details
#dyn ⇒ Object (readonly)
Returns the value of attribute dyn.
923 924 925 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 923 def dyn @dyn end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
923 924 925 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 923 def env @env end |
Instance Method Details
#[](k) ⇒ Object
925 926 927 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 925 def [] k self.all[k] end |
#[]=(k, v) ⇒ Object
929 930 931 932 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 929 def []= k, v raise "no" if v == true self.current[k] = v end |
#all ⇒ Object
934 935 936 937 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 934 def all idx = @dyn.index(false) || 0 @env[0..idx].reverse.inject { |env, scope| env.merge scope } end |
#current ⇒ Object
939 940 941 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 939 def current @env.first end |
#dynamic ⇒ Object
943 944 945 946 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 943 def dynamic idx = @dyn.index false @env[0...idx].reverse.inject { |env, scope| env.merge scope } || {} end |
#dynamic? ⇒ Boolean
948 949 950 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 948 def dynamic? @dyn[0] != false end |
#extend(dyn = false) ⇒ Object
952 953 954 955 956 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 952 def extend dyn = false @dyn.unshift dyn @env.unshift({}) @use.unshift({}) end |
#reset ⇒ Object
965 966 967 968 969 970 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 965 def reset @dyn.clear @env.clear @use.clear self.extend end |
#unextend ⇒ Object
972 973 974 975 976 977 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 972 def unextend @dyn.shift @env.shift @use.shift raise "You went too far unextending env" if @env.empty? end |
#use(id) ⇒ Object
979 980 981 982 983 984 985 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 979 def use id @env.each_with_index do |env, i| if env[id] then @use[i][id] = true end end end |
#used?(id) ⇒ Boolean
987 988 989 990 991 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 987 def used? id idx = @dyn.index false # REFACTOR u = @use[0...idx].reverse.inject { |env, scope| env.merge scope } || {} u[id] end |