select function in ruby


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


你可能感兴趣的:(select function in ruby)