TODO: Write a gem description
Add this line to your application's Gemfile:
gem 'hash_easy'
And then execute:
$ bundle
Or install it yourself as:
$ gem install hash_easy
Imagine that you need to create a hash with some levels:
my_hash = { }
%I(admin guest).each do |role|
my_hash[:data][:team][:roles][role] = { }
end
This will result in an error:
NoMethodError: undefined method `[]' for nil:NilClass
So using HashEasy as the name say is easy to initializer a hash with multilevels, avoding the necessity to initialize or declare than first.
Here some examples:
my_hash = Hash.new.bottomless
%I(admin guest).each do |role|
my_hash[:data][:team][:roles][role] = { }
end
And the result:
{:data=>{:team=>{:roles=>{:admin=>{}, :guest=>{}}}}}
- Fork it ( https://github.com/[my-github-username]/hash_easy/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request