Skip to content

Instantly share code, notes, and snippets.

@rush2sk8
Created August 16, 2019 18:53
Show Gist options
  • Save rush2sk8/768d1370e0f3f9907aa6c79a5aafeaca to your computer and use it in GitHub Desktop.
Save rush2sk8/768d1370e0f3f9907aa6c79a5aafeaca to your computer and use it in GitHub Desktop.
gets all values from a hash no matter how nester
def deep_values(h, acc = [])
return [nil] if h.nil?
case h
when Hash
return deep_values(h.values)
when Array
acc.push(*h.map { |v| deep_values(v) })
else
acc.push(h)
end
acc.flatten
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment