From: Gavin Sinclair Date: 2004-05-13T17:10:38+09:00 Subject: Re: in search of a compelling reason to use ruby.... Robert wrote: > You can make your life even simpler with: > > module Criterion > def self.create(&b) > def b.===(x); call(x);end > b > end > end > > irb(main):031:0> a = %w{a bb ccc} > => ["a", "bb", "ccc"] > irb(main):032:0> crit = Criterion.create {|x| x.length > 2} > => # > irb(main):033:0> a.grep(crit) {|x| "(#{x})"} > => ["(ccc)"] How is this simpler than a.select { |x| x.length > 2 } ? OIC. You're using the block form of grep to save yourself a map. I don't much like it, though, because the filtering predicate is removed from the place where it's used, wasting the beuaty of blocks. Clever, though, and probably useful in some situations (e.g. where you're doing *lots* of filtering and mapping :) Cheers, Gavin