0.0
No commit activity in last 3 years
No release in over 3 years
Ruby short cut for making hash
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

SimpleHash

Gem Version Build Status

Brings ES6 object initializer sugar to Ruby.

Usage

suppose you have these variables

year = 2016
month = 3
day = 30
hour = 18
minute = 50
second = 23

Build a hash requires much redundancy:

{year: year, month: month, day: day, hour: hour, minute: minute, second: second}

With SimpleHash, build like this:

SimpleHash{[:year, :month, :day, :hour, :minute, :second]}

Further, you can load the short cut by calling SimpleHash.short_cut!, this method would add a method #h to Object. Then you can build like this:

h{[:year, :month, :day, :hour, :minute, :second]}

Support ruby version

  • MRI ~> 2.1
  • rubinius ~> 3.15

This gem uses Binding#local_variable_get, makes MRI < 2.1 and rubinius < 3.15 lack of support. Using eval may solve the problem, but evaling an user passed string may cause problems.

Installation

Install the gem

gem install simple_hash

or require it in your Gemfile

gem 'simple_hash'

Development

Test:

bundle exec rspec

License

This gem is released under the MIT License