Skip to content

Instantly share code, notes, and snippets.

@redconfetti
Created August 31, 2018 03:27
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 redconfetti/3daa031f7ad4f7bd6311482d659a1aeb to your computer and use it in GitHub Desktop.
Save redconfetti/3daa031f7ad4f7bd6311482d659a1aeb to your computer and use it in GitHub Desktop.
Enumerable.find - Hash and Key and Value Match
# It does work
my_hash = {a: 1, b: 2, c: 3, d: 4, e: 5}
my_hash.find {|k,v| puts "k:#{k},v:#{v}"; v == 3}
# Output:
# k:a,v:1
# k:b,v:2
# k:c,v:3
# => [:c, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment