From: Jonathan Rochkind Date: 2011-01-14T02:55:04+09:00 Subject: Hash#select, different than documented? The documentation at: http://www.ruby-doc.org/core/classes/Hash.html#M000750 Says that Hash#select does this: Returns a new hash consisting of entries for which the block returns true. If no block is given, an enumerator is returned instead. h = { "a" => 100, "b" => 200, "c" => 300 } h.select {|k,v| k > "a"} #=> {"b" => 200, "c" => 300} h.select {|k,v| v < 200} #=> {"a" => 100} *** However, that is not the behavior I am seeing in my ruby 1.8.6. Is that documentation for a later version of ruby, in which this behavior changed? Or is the documentation just wrong? I instead get an array of pairs returned. From irb: irb(main):008:0> h = { "a" => 100, "b" => 200, "c" => 300 } => {"a"=>100, "b"=>200, "c"=>300} irb(main):009:0> h.select {|k,v| k > "a"} #=> {"b" => 200, "c" => 300} => [["b", 200], ["c", 300]] irb(main):010:0> h.select {|k,v| v < 200} #=> {"a" => 100} => [["a", 100]] Is there any other search behavior implemented on Hash I could be using instead, with more convenient behavior for finding hash subsets, and/or finding hash keys whose values are matched by a certain block? -- Posted via http://www.ruby-forum.com/.