0.0
No commit activity in last 3 years
No release in over 3 years
Enables the usage of methods instead of brackets for hashes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.11
~> 5.0
~> 10.0
 Project Readme

Methodify Hash

This is a small module which enables hashes to use methods instead of the standard bracket operator [] comparable to Hashie.

Usage

Only one hash (won't work for nested):

hash = Hash.new
hash[:bye] = 'see ya'
hash.extend(MethodifyHash::Module)
puts hash.bye

Using helper method for only one hash (works for nested):

nested_hash = { this: { really: { works: 'bye' }, great: 'see' } }
MethodifyHash.methodify(nested_hash)
puts nested_hash.this.really.works

All hashes beginning from this point:

class Hash
  include MethodifyHash::Module
end

hash = { this: 'hello' }
puts hash.this

Also hashes with strings as keys works:

string_hash = { 'hello' => 'bye' }
puts string_hash.hello

Current Issues

Tests have to be run separately to ensure everything is working correctly

Licence

The MIT License (MIT)

Copyright (c) 2016 Christian Paling

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.