No commit activity in last 3 years
No release in over 3 years
Allow hash values to be set and retrieved as if they were its attributes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme
Author
====
Niranjan Sarade

About the utility - HashKeyAsAttribute
====

In ruby, we have OpenStruct which allows the creation of data objects with arbitrary attributes.
With ruby's metaprogramming capability, we can also allow hash values to be set and retrieved as if
they were its attributes. So setting and getting the value for the key would be treated as if they
were method calls on the hash object.
If the key does not correspond to any hash entry, it should return “The key does not correspond to any hash entry” message.
The hook that has been used is Kernel's method_missing.

Example
====

require 'hash_key_as_attribute'

h = {}
h.one = 1
puts h.one #=> 1

h.two= [1,2,3,4]
puts h.two.inspect #=> [1,2,3,4]

puts h.three #=> "The key does not correspond to any hash entry"

puts h.inspect #=> {:one=>1, :two=>[1, 2, 3, 4]}

h2 = {}
h2.four = 4

h.three = h2

puts h.three.inspect #=> {:four=>4}

puts h.three.four #=> 4 


Install
====
gem install hash_key_as_attribute

(It has been pushed to http://gemcutter.org)

OR

Download the gem file from http://github.com/NiranjanSarade/hash_key_as_attribute/
gem install hash_key_as_attribute-0.0.1.gem


Uninstall
====
gem uninstall hash_key_as_attribute