binding-slicer 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +59 -12
- data/binding-slicer.gemspec +1 -1
- data/lib/binding/slicer.rb +15 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8d73511fc74eb54f16c8c8cee769fda396cc215c08c051a0cb129568872805a
|
4
|
+
data.tar.gz: 42b049546726cdfa5fc110aa4476eaf01276714b913d515c0e54ff365b47354d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95480103a19652f9f556808e82fae0b3106284057b20dea1685298f785cf7ee80a06243569bebf6977134b67b9b0aa87d3c9a5fa21ba44cb5b7c08928f89124e
|
7
|
+
data.tar.gz: 153f2f216ada01a2dbf0c6190e450ad1f473a4fd25698f6c1494c9a63c74935801a87b6bb84a4d2de8101b6650e26272e82efec186b7de5fdcf50e3189b0a81c
|
data/README.md
CHANGED
@@ -1,8 +1,65 @@
|
|
1
1
|
# Binding::Slicer
|
2
2
|
|
3
|
-
|
3
|
+
This gem let you write code to construct Hash objects much easier!
|
4
4
|
|
5
|
-
|
5
|
+
You can write:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'binding-slicer'
|
9
|
+
using Binding::Slicer
|
10
|
+
|
11
|
+
a = 1
|
12
|
+
b = 2
|
13
|
+
c = 3
|
14
|
+
|
15
|
+
binding[:a, :b, :c] #-> {a: a, b: b, c: c}
|
16
|
+
|
17
|
+
binding[:a, :b, d: 100] #-> {a: a, b: b, d: 100}
|
18
|
+
```
|
19
|
+
|
20
|
+
Or, you can use the shorter version:
|
21
|
+
|
22
|
+
```
|
23
|
+
require 'binding-slicer'
|
24
|
+
using Binding::SSlicer
|
25
|
+
|
26
|
+
a = 1
|
27
|
+
b = 2
|
28
|
+
c = 3
|
29
|
+
|
30
|
+
_[:a, :b, d: 100]
|
31
|
+
```
|
32
|
+
|
33
|
+
You should always write very stressful code, like this:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
def foo(my_argument_one, my_argument_two, my_argument_three)
|
37
|
+
options = {
|
38
|
+
my_argument_one: my_argument_one,
|
39
|
+
my_argument_two: my_argument_two,
|
40
|
+
my_argument_three: my_argument_three,
|
41
|
+
}
|
42
|
+
bar(options)
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
With this gem, you can simplify it dramatically!
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'binding-slicer'
|
50
|
+
using Binding::SSlicer
|
51
|
+
|
52
|
+
def foo(my_argument_one, my_argument_two, my_argument_three)
|
53
|
+
bar(_[:my_argument_one, :my_argument_two, :my_argument_three])
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
## TODO
|
58
|
+
|
59
|
+
* Write tests!
|
60
|
+
* Implement `_[:a, :b, :c]`
|
61
|
+
* Can we use more hash-like presentation?
|
62
|
+
* For example, `_{[:a, :b, :c]}` (Is this really better than `_[:a, :b, :c]`?)
|
6
63
|
|
7
64
|
## Installation
|
8
65
|
|
@@ -20,16 +77,6 @@ Or install it yourself as:
|
|
20
77
|
|
21
78
|
$ gem install binding-slicer
|
22
79
|
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
80
|
## Contributing
|
34
81
|
|
35
82
|
Bug reports and pull requests are welcome on GitHub at https://github.com/tagomoris/binding-slicer.
|
data/binding-slicer.gemspec
CHANGED
data/lib/binding/slicer.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
class Binding
|
2
2
|
module Slicer
|
3
3
|
module Mixin
|
4
|
-
def slice(*symbols)
|
4
|
+
def slice(*symbols, **additionals)
|
5
5
|
hash = {}
|
6
6
|
symbols.each do |name|
|
7
7
|
hash[name] = local_variable_get(name)
|
8
8
|
end
|
9
|
-
hash
|
9
|
+
hash.merge(additionals)
|
10
10
|
end
|
11
11
|
|
12
12
|
alias :"[]" :slice
|
@@ -16,4 +16,17 @@ class Binding
|
|
16
16
|
include Binding::Slicer::Mixin
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
module SSlicer
|
21
|
+
module Mixin
|
22
|
+
alias :_ :binding
|
23
|
+
end
|
24
|
+
|
25
|
+
refine Binding do
|
26
|
+
include Binding::Slicer::Mixin
|
27
|
+
end
|
28
|
+
refine Kernel do
|
29
|
+
include Binding::SSlicer::Mixin
|
30
|
+
end
|
31
|
+
end
|
19
32
|
end
|