http://ruby-doc.org/
http://ruby-doc.org/core-2.3.0/Array.html#method-i-select
[1,2,3,4,5].select { |num| num.even? } #=> [2, 4]
a = %w{ a b c d e f }
a.select { |v| v =~ /[aeiou]/ } #=> ["a", "e"]
# TODO: 使用 MySQL 的 FIND_IN_SET,必须过滤掉逗号分割符之间的空格 # http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_find-in-set custom_subjects = SpecialSubject.where('state = ? AND pid != ? ' , 1, '').select do |subject| pids = subject.pid.split(',') pids.include? pid end custom_subjects.each do |subject| if (homepage_position = subject.homepage_position.to_i) && homepage_position != 0 result_videos[homepage_position - 1] = subject end end
Ruby Select 方法与 MySQL 使用技巧
本文介绍了 Ruby 中 select 方法的使用方式,并通过实例展示了如何筛选数组中的元素。此外,还探讨了使用 MySQL 的 FIND_IN_SET 函数时需要注意的问题及解决方法。
537

被折叠的 条评论
为什么被折叠?



