Let's say you have a list in Ruby:
integer_list = [1, 2, 3, 4, 5]
Selecting only the even numbers would be easy
integer_list.select(&:even?)
But what happens, if you had a mixed list? And wanted to select only the integers From what I've learned, I would write something like this:
mixed_list = [1, 2, 3, 4, 5, 'string']
mixed_list.select { |x| x.is_a? Integer }
My question now is, is there a way to shorten this code like in the first example? Roughly like that:
mixed_list.select(&:is_a? Integer)