Skip to content

Instantly share code, notes, and snippets.

/pull_value.rb Secret

Created May 2, 2016 22:43
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 anonymous/f8ca3a643b7e1817353559d70db543f3 to your computer and use it in GitHub Desktop.
Save anonymous/f8ca3a643b7e1817353559d70db543f3 to your computer and use it in GitHub Desktop.
Does Ruby already have a deep `find` for collections ?
class Array
include Enumerable
def pull_value(val)
self.flatten.select { |element| element == val }
end
end
result = nested_array.pull_value("ham")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment