In Ruby, #find_all and #select are different (for Hashes)
In Ruby, Hash#select
returns a Hash
whereas Hash#find_all
returns an Array
.
This is because Ruby’s Hash
class defines its own #select
method, but inherits its #find_all
method from the Enumerable
module.
# select returns a Hash
{ foo: 1, bar: 2 }.select { |key, value| value.even? }
# => { :bar => 2 }
# find_all returns an Array
{ foo: 1, bar: 2 }.find_all { |key, value| value.even? }
# => [[:bar, 2]]
For more details see this StackOverflow answer.