Skip to content

Instantly share code, notes, and snippets.

@malclocke
Created September 8, 2014 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malclocke/7072185045b469f025c3 to your computer and use it in GitHub Desktop.
Save malclocke/7072185045b469f025c3 to your computer and use it in GitHub Desktop.
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