Sha256: c4b06b423c0a162aee486306804b72eabc19915c2da73786052563293d6c7b06

Contents?: true

Size: 1.01 KB

Versions: 1884

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Parser

  class StaticEnvironment
    FORWARD_ARGS = :FORWARD_ARGS
    ANONYMOUS_BLOCKARG = :ANONYMOUS_BLOCKARG

    def initialize
      reset
    end

    def reset
      @variables = Set[]
      @stack     = []
    end

    def extend_static
      @stack.push(@variables)
      @variables = Set[]

      self
    end

    def extend_dynamic
      @stack.push(@variables)
      @variables = @variables.dup

      self
    end

    def unextend
      @variables = @stack.pop

      self
    end

    def declare(name)
      @variables.add(name.to_sym)

      self
    end

    def declared?(name)
      @variables.include?(name.to_sym)
    end

    def declare_forward_args
      declare(FORWARD_ARGS)
    end

    def declared_forward_args?
      declared?(FORWARD_ARGS)
    end

    def declare_anonymous_blockarg
      declare(ANONYMOUS_BLOCKARG)
    end

    def declared_anonymous_blockarg?
      declared?(ANONYMOUS_BLOCKARG)
    end

    def empty?
      @stack.empty?
    end
  end

end

Version data entries

1,884 entries across 1,880 versions & 15 rubygems

Version Path
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
avalara_sdk-24.12.0 vendor/bundle/ruby/2.7.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
mux_ruby-3.19.0 vendor/bundle/ruby/3.2.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
mux_ruby-3.18.0 vendor/bundle/ruby/3.2.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
mux_ruby-3.17.0 vendor/bundle/ruby/3.2.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/parser-3.1.2.1/lib/parser/static_environment.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/parser-3.1.2.1/lib/parser/static_environment.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/parser-3.1.2.1/lib/parser/static_environment.rb
mux_ruby-3.15.0 vendor/bundle/ruby/3.2.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
mux_ruby-3.14.0 vendor/bundle/ruby/3.2.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
mux_ruby-3.13.0 vendor/bundle/ruby/3.2.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
mux_ruby-3.12.0 vendor/bundle/ruby/3.2.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/parser-3.1.2.1/lib/parser/static_environment.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/parser-3.1.1.0/lib/parser/static_environment.rb
mux_ruby-3.11.1 vendor/bundle/ruby/3.2.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb
mux_ruby-3.11.0 vendor/bundle/ruby/3.2.0/gems/parser-3.1.2.0/lib/parser/static_environment.rb