0.0
The project is in a healthy, maintained state
Introduce a method to get a slice Hash of the current binding.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
 Project Readme

Binding::Slicer

This gem let you write code to construct Hash objects much easier!

You can write:

require 'binding-slicer'
using Binding::Slicer

a = 1
b = 2
c = 3

binding[:a, :b, :c] #-> {a: a, b: b, c: c}

binding[:a, :b, d: 100] #-> {a: a, b: b, d: 100}

Or, you can use the shorter version:

require 'binding-slicer'
using Binding::SSlicer

a = 1
b = 2
c = 3

_[:a, :b, d: 100]

You should always write very stressful code, like this:

def foo(my_argument_one, my_argument_two, my_argument_three)
    options = {
        my_argument_one: my_argument_one,
        my_argument_two: my_argument_two,
        my_argument_three: my_argument_three,
    }
    bar(options)
end

With this gem, you can simplify it dramatically!

require 'binding-slicer'
using Binding::SSlicer

def foo(my_argument_one, my_argument_two, my_argument_three)
    bar(_[:my_argument_one, :my_argument_two, :my_argument_three])
end

TODO

  • Write tests!
  • Can we use more hash-like presentation?
    • For example, _{[:a, :b, :c]} (Is this really better than _[:a, :b, :c]?)

Installation

Add this line to your application's Gemfile:

gem 'binding-slicer'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install binding-slicer

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tagomoris/binding-slicer.

License

The gem is available as open source under the terms of the MIT License.