From: Mateusz Tybura Date: 2008-08-18T22:46:57+09:00 Subject: Re: Hash#each vs Hash#each_pair Patrick Doyle wrote: > Sorry if this is a FAQ, but I'm curious to learn the rationale behind > having Hash#each be the same as Hash#each_pair instead of > Hash#each_value. > > For my own (self-interested) case, I would prefer that Hash#each and > Array#each both iterate through the values of the container. > > So, why are these different? > > --wpd #!/usr/bin/ruby hash = {1 => 'one', 2 => 'two', 3 => 'three'} p "p hash : #{hash}" p "hash.each" hash.each do |e| #e is [key,value] p e end p "hash.each_pair" hash.each_pair do |k,v| #k and v class as in hash p "#{k}=#{v}" end p "hash.each_value" hash.each_value do |e| #e is value p e end -- Posted via http://www.ruby-forum.com/.