class Cri::ArgumentList
A list of arguments, which can be indexed using either a number or a symbol.
Public Class Methods
new(raw_arguments, explicitly_no_params, param_defns)
click to toggle source
# File lib/cri/argument_list.rb, line 20 def initialize(raw_arguments, explicitly_no_params, param_defns) @raw_arguments = raw_arguments @explicitly_no_params = explicitly_no_params @param_defns = param_defns load end
Public Instance Methods
[](key)
click to toggle source
# File lib/cri/argument_list.rb, line 28 def [](key) case key when Symbol @arguments_hash[key] when Integer @arguments_array[key] else raise ArgumentError, "argument lists can be indexed using a Symbol or an Integer, but not a #{key.class}" end end
each() { |e| ... }
click to toggle source
# File lib/cri/argument_list.rb, line 39 def each return to_enum(__method__) unless block_given? @arguments_array.each { |e| yield(e) } self end
load()
click to toggle source
# File lib/cri/argument_list.rb, line 58 def load @arguments_array = [] @arguments_hash = {} arguments_array = @raw_arguments.reject { |a| a == '--' }.freeze if !@explicitly_no_params && @param_defns.empty? # No parameters defined; ignore @arguments_array = arguments_array return end if arguments_array.size != @param_defns.size raise ArgumentCountMismatchError.new(@param_defns.size, arguments_array.size) end arguments_array.zip(@param_defns).each do |(arg, param_defn)| arg = param_defn.transform ? param_defn.transform.call(arg) : arg @arguments_hash[param_defn.name.to_sym] = arg @arguments_array << arg end end
method_missing(sym, *args, &block)
click to toggle source
Calls superclass method
# File lib/cri/argument_list.rb, line 46 def method_missing(sym, *args, &block) if @arguments_array.respond_to?(sym) @arguments_array.send(sym, *args, &block) else super end end
respond_to_missing?(sym, include_private = false)
click to toggle source
Calls superclass method
# File lib/cri/argument_list.rb, line 54 def respond_to_missing?(sym, include_private = false) @arguments_array.respond_to?(sym) || super end