to_hash/to_a check in Hash[] should only be done when only one argument is given; ref #2594

parent 02b2ac8d
......@@ -24,6 +24,8 @@ class Hash
#
def self.[](*object)
length = object.length
if length == 1
o = object[0]
if o.respond_to?(:to_hash)
h = Hash.new
......@@ -47,9 +49,12 @@ class Hash
end
return h
end
raise ArgumentError, 'odd number of arguments for Hash' unless object.length % 2 == 0
end
unless length % 2 == 0
raise ArgumentError, 'odd number of arguments for Hash'
end
h = Hash.new
0.step(object.length - 2, 2) do |i|
0.step(length - 2, 2) do |i|
h[object[i]] = object[i + 1]
end
h
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment