Skip to content

Instantly share code, notes, and snippets.

@fallengiants
Created March 29, 2013 20:17
Show Gist options
  • Select an option

  • Save fallengiants/5273343 to your computer and use it in GitHub Desktop.

Select an option

Save fallengiants/5273343 to your computer and use it in GitHub Desktop.
hash.search
class Hash
def search(m)
retval = []
self.each_pair do |k,v|
if v.kind_of?(Hash)
v.search(m).each {|u| retval << [k,*u]}
else
rets = case m
when Regexp
v.to_s =~ m
when Class
v.kind_of?(m)
else
v == m
end
retval << k if rets
end
end
retval
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment