Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Ruby short cut for making hash

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages