Skip to content
/ dotize Public

Dig into a Hash with a dot-delimited string

Notifications You must be signed in to change notification settings

odlp/dotize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dotize

Build Status

Access values from a deeply-nested Hash using a simple string:

my_hash = {'a' => {'b' => {'c' => 123}}}
my_hash.extend(Dotize)
my_hash.dot('a.b.c') # => 123

If a value isn't found, nil is returned by default:

my_hash.dot('a.b.z.z.z') # => nil

You can provide a block to override the default, like Ruby's Hash#fetch:

my_hash.dot('a.b.z.z.z') { |el| 2 + 2 } # => 4

Development

  • Run specs via rake or bundle exec rspec

Credits

The name of this is inspired-by copied from github.com/vardars/dotize, a Javascript equivalent.

About

Dig into a Hash with a dot-delimited string

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published