[Awesome Ruby Gem] Use hashie gem to extend Hashes and make them more useful
hashie
Hashie is a growing collection of tools that extend Ruby Hashes and make them more useful.
This article is about how to use Hashie::Mash
to access hash value with symbol key or dynamic method.
Visit hashie/hashie: Hashie is a collection of classes and mixins that make Ruby hashes more powerful. - https://github.com/hashie/hashie#mash
to learn more examples.
Installation
You can install it as a gem:
1 | gem install hashie |
or add it into a Gemfile (Bundler):
1 | # Gemfile |
Then, run bundle install
.
1 | bundle install |
Usage
1 | > json = JSON.parse('{"foo": 1}') |
Use Hashie::Mash
to access hash value with symbol or dynamic method.
1 | > mash = Hashie::Mash.new(JSON.parse('{"foo": 1}')) |
References
[2] hashie | RubyGems.org | your community gem host - https://rubygems.org/gems/hashie/