From: benjohn@... Date: 2008-04-30T19:20:15+09:00 Subject: Re: Question on Procs > What is the difference between this: *snip* > filter_ths = make_filter( lambda { |x| x.ordinal =~ /th$/ ? true : > false }, list) > > p filter_ths > > and this: *snip* > filter_ths = make_filter( lambda { |x| x.ordinal =~ /th$/ ? true : > false }) > > p filter_ths.call(list) > > I am not clear on the advantage of returning proc object vs just the > result as an array. TIA. The difference is abstraction, if I understand your question. In the first case, you've filtered something (an enumerable type) and built a result array. In the second case, you have built a little machine (the proc) that will take an enumerable type and filter it to give an array. This machine is probably a more reusable thing. As a motivating example, lets say you have an object called Trawler (or a group of objects working together) that find interesting web pages to store. In the former case, Trawler will have to tell you about some web pages it's found that might be interesting. You can filter them, and then tell it the ones you want it to store. In the latter case, you can give Trawler a filter, and it can then be autonimous - it can filter pages to see if they're interesting. :-) Or have I totally missed the right end of your question? You can write these more concisely like this (I've not tested this)... cool_pages = web_pages.find_all {|x| is_this_a_cool_page(x)} verses... page_filter = proc {|array| array.find_all {|x| is_this_a_cool_page?(x)}} cool_pages = page_filter.call(web_pages) Cheers, Benjohn