Skip to content

Instantly share code, notes, and snippets.

@ashaw
Created August 22, 2013 15:35
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 ashaw/6308796 to your computer and use it in GitHub Desktop.
Save ashaw/6308796 to your computer and use it in GitHub Desktop.
class DeepFinder
attr_reader :accum
def initialize(h, key)
@accum = []
@h = h
@key = key
dig @h
end
def dig(h)
h.each do |k,v|
if k == @key
@accum << h[k]
elsif v.is_a?(Hash)
dig(h[k])
elsif v.is_a?(Array)
v.each do |item|
if item.is_a?(Hash)
dig(item)
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment