grep numbers : grep « Array « Ruby






grep numbers


data = [1, 17, 3.0, 4]
ints = data.grep(Integer)           # => [1, 17, 4]: only integers
small = ints.grep(0..9)             # [1,4]: only in range

 








Related examples in the same category

1.Get array element by using grep
2.grep /[^g]/
3.Start with 'p'