Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def value_of_first_matching_key_in_hash(hash, array_of_keys)
end
describe do
it 'searches a hash for an array of keys and returns the value of the first found' do
keys = [:a, :b, :c]
hash = {:c => 3, :b => 2, :a => 1}
expect(value_of_first_matching_key_in_hash(hash, keys)).to eql 1
hash = {:z => 1, :b => 2, :c => 3}
expect(value_of_first_matching_key_in_hash(hash, keys)).to eql 2
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment