Hi --

On Sun, 25 Oct 2009, Rajinder Yadav wrote:

> Matt Beckley wrote:
>> Now I wanna take my array and apply a
>> method to it that will check which elements are less 21 but more then
>> 10. For you math types 10<x<21.
>> 
>> a = nums1.reject {|x| x<10 && x>21}
>
> What you want is:
>
> a = nums.find_all { |n| n > 10 && n < 21 }
>
> OR using Range
>
> a = nums.find_all { |n| (11..20) === n }

You can also do:

   a = nums.grep(11..20)

which is a wrapper for a bunch of calls to ===.


David

-- 
The          Ruby training with D. Black, G. Brown, J.McAnally
Compleat     Jan 22-23, 2010, Tampa, FL
Rubyist      http://www.thecompleatrubyist.com

David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com)