ruby-1.9.2-p290 :021 > lessons.find{|i| i.show_scenario_id == 836} => #<Scenario id: 6, item_group_id: 106, name: "Do you prefer X or Y?", show_scenario_id: 836, position: 1, show_link: nil, created_at: "2012-03-05 07:44:17", updated_at: "2012-03-05 07:44:17", image_url: nil> ruby-1.9.2-p290 :022 > lessons.select{|i| i.show_scenario_id == 836} => [#<Scenario id: 6, item_group_id: 106, name: "Do you prefer X or Y?", show_scenario_id: 836, position: 1, show_link: nil, created_at: "2012-03-05 07:44:17", updated_at: "2012-03-05 07:44:17", image_url: nil>]
ruby-1.9.2-p290 :024 > lessons.find_all{|i| i.show_scenario_id == 836}
=> [#<Scenario id: 6, item_group_id: 106, name: "Do you prefer X or Y?", show_scenario_id: 836, position: 1, show_link: nil, created_at: "2012-03-05 07:44:17", updated_at: "2012-03-05 07:44:17", image_url: nil>]
今天需要对数组的数据进行查找,遇到了此类问题。find方法只查询第一条记录,而select方法同find_all 一样是查询所有记录。