On 14.01.2008 17:08, Mark Mr wrote: > Todd Burch wrote: >> Mark Mr wrote: >> >>> Todd, could you give me an example of how you might use .collect for >>> this? I tried doing it but I'm not quite sure i understand how to use it >>> in this situation. Keep in mind that for @this_question.answers.each, >>> every element of that is an answer object, not sure if that affects >>> methods that are performed on arrays. >> Actually, Robert's example with .find should suffice. .find is also in >> the Enumerable class. >> >> If you REALLY want an example with .collect, I can write one up for >> illustration purposes. The type of object in your array really does not >> matter. >> >> Todd > > Ok well i tried again with .find and it wasnt working but then I > replaced it with .detect and it worked fine. So i guess there's a > difference there. Thanks for the help though :) As far as I know #detect and #find are aliases so I suspect you changed something else, too. irb(main):001:0> a=%w{foo bar baz dada} => ["foo", "bar", "baz", "dada"] irb(main):002:0> a.detect {|s| s.length == 4} => "dada" irb(main):003:0> a.detect {|s| s.length == 3} => "foo" irb(main):004:0> a.find {|s| s.length == 3} => "foo" irb(main):005:0> a.select {|s| s.length == 3} => ["foo", "bar", "baz"] irb(main):006:0> Kind regards robert