zoukankan      html  css  js  c++  java
  • rails 数组中find和select方法的区别

    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 一样是查询所有记录。

  • 相关阅读:
    [Heoi2013]Alo
    10.24 考试
    第八周作业
    第七周作业
    第六周作业
    第五周作业
    第四周作业
    求最大值及其下标
    查找整数
    抓老鼠啊~亏了还是赚了?
  • 原文地址:https://www.cnblogs.com/yanmiao/p/2453617.html
Copyright © 2011-2022 走看看