Skip to content

Instantly share code, notes, and snippets.

@Heavyblade
Last active June 4, 2019 21:50
Show Gist options
  • Select an option

  • Save Heavyblade/4362181389b207edb596abb367aba78b to your computer and use it in GitHub Desktop.

Select an option

Save Heavyblade/4362181389b207edb596abb367aba78b to your computer and use it in GitHub Desktop.
dig.rb
def dig(row,array_of_keys)
return row if array_of_keys.count == 0
current = case row
when Hash
current = row[array_of_keys.shift]
when Array
current = (row.find { |x| x.key?(key)} ||{})[key]
else
nil
end
dig(current, array_of_keys)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment