From: Bertram Scharpf Date: 2010-01-02T22:48:11+09:00 Subject: Re: can't understand for this each Hi, Am Samstag, 02. Jan 2010, 21:20:02 +0900 schrieb Ruby Newbee: > what's each{ .. } in the find_all method? > > class Hash > def find_all > new_hash = Hash.new > each { |k,v| new_hash[k] = v if yield(k, v) } > new_hash > end > end `Hash#each' is not `Array#each'. It is descibed in . It does something like class Hash def each keys.each { |k| yield k, self[ k] } end end A remarkable aspect is that `Hash#each' yields two values so that everywhere in Enumerable's descriptions "{ |obj| ... }" has to be replaced with "{ |k,v| ... }" or even "|(k,v)|". For example, you have to call hash.each_with_index { |(k,v),i| ... } Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany * Support `String#notempty?': .