RubyGems Navigation menu

hashlib 0.0.1

Hashlib: Utility methods for Ruby Hashes ======================================== Hashlib extends the base Ruby Hash class with new methods that offer useful functionality for working with hashes, specifically addressing handling of deeply-nested Hashes for representing rich object structures. get --- The get method is used to allow for retrieval of a deeply-nested value in a hash structure. Given: ```ruby config = { :global => { :security => { :sslroot => '/etc/ssl' }, :pidfile => '/var/run/example.pid' }, :plugins => ['logger', 'cruncher'] } ``` The following statements are equivalent: ```ruby config.get('global.security.sslroot') # returns the same thing as config[:global][:security][:sslroot] ``` However, let's say you attempted to get <code>config[:global][:adapters][:path]</code>. You would get a nasty NilError because <code>:adapters</code> doesn't exist. However, if you used <code>config.get('global.adapters.path')</code>, the result would just be <code>nil</code>. _get_ also takes a second argument that let's you specify the default value if the given path is not found. This lets you very easily work with rich nested hashes while also specifying sane defaults for missing values. set --- The set method is the opposite of get. It creates one or more intermediary hashes along a specified path and setting the value for the last component. ```ruby y = {} y.set('this.is.a.number', 4) # results in # {"this"=>{ # "is"=>{ # "a"=>{ # "number"=>4 # }}}} ```

Gemfile:
= Copy to clipboard Copied!

install:
=

Versions:

  1. 0.0.35 - November 14, 2013 (5.5 KB)
  2. 0.0.34 - November 14, 2013 (5.5 KB)
  3. 0.0.33 - November 14, 2013 (5 KB)
  4. 0.0.32 - November 14, 2013 (5 KB)
  5. 0.0.31 - November 14, 2013 (5 KB)
  6. 0.0.1 - March 14, 2013 (5 KB)
Show all versions (31 total)

Owners:

Authors:

  • Gary Hetzel

SHA 256 checksum:

= Copy to clipboard Copied!

Total downloads 115,344

For this version 2,928

Licenses:

N/A

Required Ruby Version: None

Links: