Project

openhash

0.0
No commit activity in last 3 years
No release in over 3 years
OpenHash lets Hash called and assigned by the key in chainable way.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 2.0
~> 12.3
~> 3.0
 Project Readme

OpenHash

OpenHash lets Hash called and assigned by the key in chainable way.

Installation

# Manually from RubyGems.org
$ gem install openhash

# Or Gemfile if you are using Bundler
$ gem openhash

Usage

person = OpenHash.new(name: "John", hometown: { city: "London" }, pets: [{ name: "Mia", animal: "Cat" }])
person.name #=> "John"
person.hometown.city #=> "London"
person.pets[0].name #=> "Mia"

person = OpenHash.new
person.name = "Lion"
person.hometown.city = "Paris"
person.parents.father.name = "Heron"
person #=> { name: "Lion", hometown: { city: "Paris" }, parents: { father: { name: "Heron" } } }

Known Issue

Since Ruby doesn't support to override logic oprators, so please pay attention to use oprators below when you are using OpenHash:

  • &&, and
  • ||, or
  • &.

The most recommend way once you have to do some logic checking:

person = OpenHash.new

# Wrong
city = person.city || "London"

# Right
city = person.city.nil? ? "London" : person.city

# Wrong
state = person.is_succeed && "Success"

# Right
state = "Success" if !person.is_succeed.nil?

# Wrong
person.city&.upcase

# Right
!person.city.nil? && person.city.upcase

License

Released under the MIT license. See LICENSE file for details.