Skip to content

Instantly share code, notes, and snippets.

@chsh
Created October 24, 2014 03:00
Show Gist options
  • Select an option

  • Save chsh/c66c228e955f74789781 to your computer and use it in GitHub Desktop.

Select an option

Save chsh/c66c228e955f74789781 to your computer and use it in GitHub Desktop.
simple deep hash scanner
# hash = { a: { b: 1 } }
# path hash, :a, :b -> 1
def path(source, *keys)
return nil unless source
return nil unless source.respond_to? :[]
keys.each do |key|
return nil unless source.respond_to? :[]
source = source[key]
return nil unless source
end
source
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment