This is all I'll say, all you non-Rubyists out there, this is what you are missing:
array_one = [1, 2, 3, 4, 5]
array_two = array_one.select { |a| a > 2 }
Select iterates through array_one picking the items in the array that return true to the condition passed into #select block.
1.9.3p286 :004 > array_one = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
1.9.3p286 :005 > array_two = array_one.select { |a| a > 2 }
=> [3, 4, 5]
1.9.3p286 :006 >
No comments:
Post a Comment