ruby - Use hash select for an array -



ruby - Use hash select for an array -

i have hash

h = {a=> 1, b=> 2, c=> 3}

and array

a = [a, b]

is possible utilize

h.select {|k,v| k == array_here?}

to select elements array exists in hash?

i found solution

h.select {|k,v| a.include?(k) }

you're going backwards. seek this:

a.select {|e| h.has_key? e }

ruby

Comments

Popular posts from this blog

java - How to pass parameters between Request-Scoped Controllers? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -