Method: HTTPClient::Util#argument_to_hash

Defined in:
lib/httpclient/util.rb

#argument_to_hash(args, *field) ⇒ Object

Keyword argument to hash helper.

args

given arguments.

*field

a list of arguments to be extracted.

Returns hash which has defined keys. When a Hash given, returns it including undefined keys. When an Array given, returns a Hash which only includes defined keys.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/httpclient/util.rb', line 132

def argument_to_hash(args, *field)
  return nil if args.empty?
  if args.size == 1 and Hash === args[0]
    h = args[0]
    if field.any? { |f| h.key?(f) }
      return h
    end
  end
  h = {}
  field.each_with_index do |e, idx|
    h[e] = args[idx]
  end
  h
end