module HTTPClient::Util
def hash_find_value(hash, &block)
def hash_find_value(hash, &block) v = hash.find(&block) v ? v[1] : nil end
def keyword_argument(args, *field)
end
...
def my_method(a, b, c)
instead of;
my_method(:b => 2, :a = 1)
my_method(1, 2, 3)
end
...
a, b, c = keyword_argument(args, :a, :b, :c)
def my_method(*args)
include Util
You can extract 3 arguments (a, b, c) with:
*field:: a list of arguments to be extracted.
args:: given arguments.
Keyword argument helper.
def keyword_argument(args, *field) if args.size == 1 and args[0].is_a?(Hash) args[0].values_at(*field) else args end end
def uri_dirname(uri)
def uri_dirname(uri) uri = uri.clone uri.path = uri.path.sub(/\/[^\/]*\z/, '/') uri end
def uri_part_of(uri, part)
* the same port number
* the same host String (no host resolution or IP-addr conversion)
* the same scheme
Returns true if the given 2 URIs have a part_of relationship.
def uri_part_of(uri, part) ((uri.scheme == part.scheme) and (uri.host == part.host) and (uri.port == part.port) and uri.path.upcase.index(part.path.upcase) == 0) end
def urify(uri)
def urify(uri) if uri.nil? nil elsif uri.is_a?(URI) uri else URI.parse(uri.to_s) end end