Using Ruby, what is the most efficient way to check if any key in a hash matches any values within a
Posted
by Jason
on Stack Overflow
See other posts from Stack Overflow
or by Jason
Published on 2010-05-05T01:36:11Z
Indexed on
2010/05/05
1:58 UTC
Read the original article
Hit count: 235
I want to compare the keys in a hash of parameters against an array of elements for a match.
For example:
params = {"key1", "key2", "key3"}
params_to_match = ["key2","key3"]
I could do this, but I'm sure there is a much more elegant way to acheive the same result
params.each_key{|key|
if params_to_match.include?(key.to_s)
return
end
}
© Stack Overflow or respective owner