No commit activity in last 3 years
No release in over 3 years
A Hashie::Mash knockoff
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
~> 3.3

Runtime

~> 1.8
~> 0.1
 Project Readme

HashieMashKnockoff

  • A Hashie::Mash knockoff
  • This is a prototype
  • Built and tested with Ruby 2.2.3

Setup

Add it to your Gemfile or...

gem install hashie_mash_knockoff

Test

bundle exec rspec

Usage

require 'hashie_mash_knockoff'

# access hash keys with method calls
hash     = { a: 'b', c: { d: 'e' }, f: {} }
hashie_mash_knockoff = HashieMashKnockoff.new(hash)
hashie_mash_knockoff.a         # returns 'b'
hashie_mash_knockoff.a = ''    # raises NoMethodError
hashie_mash_knockoff[:a]       # returns 'b'
hashie_mash_knockoff[:a] = ''  # raises NoMethodError
hashie_mash_knockoff.c         # returns instance of HashIsh w/ hash of { d: 'e' }
hashie_mash_knockoff.c.class   # returns HashIsh
hashie_mash_knockoff[:c]       # returns { d: 'e' }
hashie_mash_knockoff[:c].class # returns Hash
hashie_mash_knockoff.c.d       # returns 'e'
hashie_mash_knockoff.f         # returns {}
hashie_mash_knockoff.f.class   # returns Hash
hashie_mash_knockoff[:f]       # returns {}
hashie_mash_knockoff[:f].class # returns Hash

# set default values
hash     = { a: nil, b: { c: false }, d: { e: '>_<' } }
defaults = { a: 123, b: { c: true  }, d: { e: 'ಠ_ಠ' } }
hashie_mash_knockoff = HashieMashKnockoff.new(hash, defaults)
hashie_mash_knockoff.a   # returns 123,  overrides falsey nil
hashie_mash_knockoff.b.c # returns true, overrides falsey false
hashie_mash_knockoff.d.e # returns '>_<', not overriden due to '>_<' being truthy

License

The gem is available as open source under the terms of the MIT License.