D
Daniel Schierbeck
The current implementation of Hash#each[1]:
# File lib/facets/core/hash/each.rb, line 19
def each(&yld)
case yld.arity
when 0
when 1
each_value{|v| yield(v)}
else
each_pair{|k,v| yld.call(k,v)}
end
self
end
To me it looks like we're creating more Proc objects than necessary.
Would this not suffice?
def each(&block)
if block.arity < 2
each_value(&block)
else
each_pair(&block)
end
end
Cheers,
Daniel
[1] <http://facets.rubyforge.org/api/core/classes/Hash.html#M000153>
# File lib/facets/core/hash/each.rb, line 19
def each(&yld)
case yld.arity
when 0
when 1
each_value{|v| yield(v)}
else
each_pair{|k,v| yld.call(k,v)}
end
self
end
To me it looks like we're creating more Proc objects than necessary.
Would this not suffice?
def each(&block)
if block.arity < 2
each_value(&block)
else
each_pair(&block)
end
end
Cheers,
Daniel
[1] <http://facets.rubyforge.org/api/core/classes/Hash.html#M000153>