Skip to content

ThiagoAnunciacao/hash_easy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HashEasy

TODO: Write a gem description

Installation

Add this line to your application's Gemfile:

gem 'hash_easy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hash_easy

Usage

Bottomless

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=>{}}}}}

Contributing

  1. Fork it ( https://github.com/[my-github-username]/hash_easy/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

A gem with some helpers to work with hash

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages