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.


1548
1549
1550
1551
1552
# File 'lib/ruby_parser_extras.rb', line 1548

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

Instance Attribute Details

#dynObject (readonly)

Returns the value of attribute dyn


1523
1524
1525
# File 'lib/ruby_parser_extras.rb', line 1523

def dyn
  @dyn
end

#envObject (readonly)

Returns the value of attribute env


1523
1524
1525
# File 'lib/ruby_parser_extras.rb', line 1523

def env
  @env
end

Instance Method Details

#[](k) ⇒ Object


1525
1526
1527
# File 'lib/ruby_parser_extras.rb', line 1525

def [] k
  self.all[k]
end

#[]=(k, v) ⇒ Object


1529
1530
1531
1532
# File 'lib/ruby_parser_extras.rb', line 1529

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

#allObject


1534
1535
1536
1537
# File 'lib/ruby_parser_extras.rb', line 1534

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

#currentObject


1539
1540
1541
# File 'lib/ruby_parser_extras.rb', line 1539

def current
  @env.first
end

#extend(dyn = false) ⇒ Object


1543
1544
1545
1546
# File 'lib/ruby_parser_extras.rb', line 1543

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

#resetObject


1554
1555
1556
1557
1558
# File 'lib/ruby_parser_extras.rb', line 1554

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

#unextendObject


1560
1561
1562
1563
1564
# File 'lib/ruby_parser_extras.rb', line 1560

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