Kang-Kyu Lee

July 12, 2026

"select" aka "filter"

Remember "map" and "collect"? Ruby did it again.

"select" and "filter" do exactly the same thing. They pick the items that fit some condition, from a list.

numbers = [0, 4, 2, 3, 9, 8]
numbers.select {|n| n.odd? }
#=> [3, 9]
numbers.filter {|n| n.odd? }
#=> [3, 9]

There's more than one way, remember?

See you next time!

About Kang-Kyu Lee

I love hamburgers. I will share my experiences with Ruby and YouTube