Project

dotize

0.0
No commit activity in last 3 years
No release in over 3 years
Dig into a deeply-nested Hash with a dot-delimited string
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 0.10
~> 10.0
~> 3.0
 Project Readme

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.