Forum: Ruby on Rails strange has_many array problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
858392acd1398aa6071fb1d44cc33842?d=identicon&s=25 John Smilanick (Guest)
on 2006-03-31 01:05
(Received via mailing list)
I have a class that has_many :visits, I want to search through the
visits to get only ones that are committed:
I thought it would be as easy as:
==================
   visits.find_all do |visit|
     visit.coming?
   end
=================

but this always returns the entire list of visits. The only way to
get it to work is to put the visits into a new array first:
=================
   Array.new(visits).find_all do |visit|
     visit.coming?
   end
==================

Can someone explain this to me?

-John

--
John Smilanick
Computing Staff - Webmaster
Kavli Institute for Theoretical Physics
University of California, Santa Barbara
jsmilani@kitp.ucsb.edu
(805) 893-6307
27c170f482104299af279902be0a9c26?d=identicon&s=25 Trevor Squires (Guest)
on 2006-03-31 02:21
(Received via mailing list)
Hi John,

Using your example:

visits.each do |visit|
   visit.coming?
end

HTH
Trevor
--
Trevor Squires
http://somethinglearned.com
This topic is locked and can not be replied to.