class Cmds::ERBContext

Attributes

args[R]

Public Class Methods

new(args, kwds, tokenize_options_opts: {}) click to toggle source
# File lib/cmds/erb_context.rb, line 5
def initialize args, kwds, tokenize_options_opts: {}
  @args = args
  @kwds = kwds
  @arg_index = 0
  @tokenize_options_opts = tokenize_options_opts
end

Public Instance Methods

arg() click to toggle source
# File lib/cmds/erb_context.rb, line 40
def arg
  @args.fetch(@arg_index).tap {@arg_index += 1}
end
get_binding() click to toggle source
# File lib/cmds/erb_context.rb, line 36
def get_binding
  ::Kernel.send :binding
end
method_missing(sym, *args, &block) click to toggle source
Calls superclass method
# File lib/cmds/erb_context.rb, line 12
    def method_missing sym, *args, &block
      if args.empty? && block.nil?
        if sym.to_s[-1] == '?'
          key = sym.to_s[0...-1].to_sym
          # allow `false` to be omitted as well as missing and `nil`
          # by returning `nil` if the value is "false-y"
          @kwds[key] if @kwds[key]
        else
          if @kwds.key? sym
            @kwds[sym]
          elsif @kwds.key? sym.to_s
            @kwds[sym.to_s]
          else
            ::Kernel.raise ::KeyError.new ::NRSER.squish <<-END
              couldn't find keys #{ sym.inspect } or #{ sym.to_s.inspect }
              in keywords #{ @kwds.inspect }
            END
          end
        end
      else
        super sym, *args, &block
      end
    end