Skip to content

karloku/simple_hash

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Packages

No packages published

Languages