Skip to content

Instantly share code, notes, and snippets.

@liaden
Created October 15, 2015 21:12
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 liaden/2748c39a367fb8f4a5a9 to your computer and use it in GitHub Desktop.
Save liaden/2748c39a367fb8f4a5a9 to your computer and use it in GitHub Desktop.
def level(hash, index)
if level == 1
return if block_given?
yield hash.values
else
hash.values
end
end
# or hash.values.reduce(Set.new) ....
hash.values.map { |subhash| level(subhash, index-1) }.flatten.uniq
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment