From: Daniel DeLorme Date: 2007-06-22T09:04:04+09:00 Subject: Re: Behaviour of Enumerables reject vs. select mixed into Hash Trans wrote: > module Enumerable > def select(&blk) > o = self.class.new > each{|*e| o << e if blk[*e]} > end > end > > class Hash > def <<(e) > self[e[0]] = e[1] > end > end > > The downside here is, it is less efficient and breaks backward > compatibility. Why the compatibility breakage? The same could be implemented to be fully backwards compatible: module Enumerable def select(&blk) o = respond_to?(:<<) ? self.class.new : Array.new each{|*e| o << e if blk[*e]} end end Daniel