[Ruby] a lumpy hash
Ryan Davis
ryand-ruby at zenspider.com
Thu Aug 17 13:16:39 PDT 2006
On Aug 17, 2006, at 12:38 PM, Aaron Johnson wrote:
> irb(main):027:0> h.each_with_index do |k,v,i|
> irb(main):028:1* puts i
> irb(main):029:1> puts v
> irb(main):030:1> puts k
> irb(main):031:1> end
h.each_with_index do |(k,v),i|
# ...
end
the short answer is: because. The longer answer is that when you
don't do _with_index you're still lumping them in (use one arg to
see) but you're getting splatted implicitly so your two args get
values. When you use _with_index you're getting an array of the pair
and the index.
More information about the Ruby
mailing list