Sha256: 8e1f89d77a23fba2e25a8e941af4cbb622f4e35d9ac4f24bb7c9115c028c91b8

Contents?: true

Size: 575 Bytes

Versions: 3

Compression:

Stored size: 575 Bytes

Contents

class Cmds
  class ERBContext < BasicObject
    def initialize args, kwds
      @args = args
      @kwds = kwds
      @arg_index = 0
    end

    def method_missing sym, *args, &block
      if args.empty? && block.nil?
        if sym.to_s[-1] == '?'
          key = sym.to_s[0...-1].to_sym
          @kwds[key]
        else
          @kwds.fetch sym
        end
      else
        super
      end
    end

    def get_binding
      ::Kernel.send :binding
    end

    def arg
      @args.fetch(@arg_index).tap {@arg_index += 1}
    end
  end # end ERBContext
end # class Cmds

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cmds-0.0.6 lib/cmds/erb_context.rb
cmds-0.0.5 lib/cmds/erb_context.rb
cmds-0.0.4 lib/cmds/erb_context.rb