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.

Revisions

  1. rush2sk8 created this gist Aug 16, 2019.
    12 changes: 12 additions & 0 deletions deep_values.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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