class RubyNext::Language::Rewriters::Base::LocalsTracker
Attributes
stacks[R]
Public Class Methods
new()
click to toggle source
# File lib/ruby-next/language/rewriters/base.rb, line 20 def initialize @stacks = [] end
Public Instance Methods
[](name, suffix = nil)
click to toggle source
# File lib/ruby-next/language/rewriters/base.rb, line 29 def [](name, suffix = nil) fetch(name).then do |name| next name unless suffix :"#{name}#{suffix}__" end end
fetch(name) { || ... }
click to toggle source
# File lib/ruby-next/language/rewriters/base.rb, line 40 def fetch(name) ind = -1 loop do break stacks[ind][name] if stacks[ind].key?(name) ind -= 1 break if stacks[ind].nil? end.then do |name| next name unless name.nil? return yield if block_given? raise ArgumentError, "Local var not found in scope: #{name}" end end
key?(name)
click to toggle source
# File lib/ruby-next/language/rewriters/base.rb, line 36 def key?(name) !!fetch(name) { false } # rubocop:disable Style/RedundantFetchBlock end
with(**locals) { || ... }
click to toggle source
# File lib/ruby-next/language/rewriters/base.rb, line 24 def with(**locals) stacks << locals yield.tap { stacks.pop } end