binding-slicer 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4036177cd36699979414bc4d1b529a7ab422f42188a7b39a4f0763f1ae05e03
4
- data.tar.gz: adecb461db3d619a483c63a5e5cb54e0afc51238a0e00633553f812a2357c543
3
+ metadata.gz: b8d73511fc74eb54f16c8c8cee769fda396cc215c08c051a0cb129568872805a
4
+ data.tar.gz: 42b049546726cdfa5fc110aa4476eaf01276714b913d515c0e54ff365b47354d
5
5
  SHA512:
6
- metadata.gz: ad773966d5b0c9624b79d0ee3b01aab6db7b96edde88592af5390010ee0064ad68b0f44534b9db8a9bc06510472e99fc17841674f9f1ed24e42ebafb76c48d80
7
- data.tar.gz: 6d5abbc945272e4c53866a7ba637af85eef8d68b6bcfb6970b9f4a106e32cb2b7ed4dd022f5be0320b81116f2e8d4f5e95f9867463c9d8bdbcdc523a1936ca04
6
+ metadata.gz: 95480103a19652f9f556808e82fae0b3106284057b20dea1685298f785cf7ee80a06243569bebf6977134b67b9b0aa87d3c9a5fa21ba44cb5b7c08928f89124e
7
+ data.tar.gz: 153f2f216ada01a2dbf0c6190e450ad1f473a4fd25698f6c1494c9a63c74935801a87b6bb84a4d2de8101b6650e26272e82efec186b7de5fdcf50e3189b0a81c
data/README.md CHANGED
@@ -1,8 +1,65 @@
1
1
  # Binding::Slicer
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/binding/slicer`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This gem let you write code to construct Hash objects much easier!
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "binding-slicer"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["TAGOMORI Satoshi"]
5
5
  spec.email = ["tagomoris@gmail.com"]
6
6
 
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binding-slicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi