fancy_to_proc 0.1.1 → 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
  SHA1:
3
- metadata.gz: ae960da5e4467e8dd224664027b163b1cf2b786e
4
- data.tar.gz: 27c2223f8297de508a74062895d307b6eb50fc68
3
+ metadata.gz: 6d0d378fd1815f35453d06e44ca5012d21f55eb3
4
+ data.tar.gz: 56e8b70b14b3a60e89894d2d6ceba931ebc3c52f
5
5
  SHA512:
6
- metadata.gz: d6467c9d907e3a5b65d0918c397ffe380ecee0b0cbbb0cbf591d97d08189dabadda22863f85340e459ce96881d79a033bf6fcee6b3e366b1e33608a0d6ddcf8f
7
- data.tar.gz: 1e2b09e9e562eb1f3fe68d5b1dd5a7ce5ae5516cc8fd0a47c1d67160a267c4c5977d3c705b13dcfc16daa0314c39c5839241e337927d0f4019aa20580ff2220e
6
+ metadata.gz: 793358d118d5927f34d63ad7be85dc1bf343e257395c63f228e9e1926456dea1df19e2256129f124e7e9243083e50afad6efb602152a5584d0739fd7521642ad
7
+ data.tar.gz: 9ad1da09a2d5eea8a373b0fa211fb30e07df71b19dda82b63d2d5de19c088ce90a3f329eca874257a20dc0be194ba55c6c6a3ad11d0e5509c10341143f7e0ae8
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Fancy to_proc
1
+ # 🎩 Fancy to_proc
2
2
 
3
3
  Have you ever wished Symbol#to_proc was chainable and took arguments?
4
4
 
@@ -7,7 +7,8 @@ Have you ever wished Symbol#to_proc was chainable and took arguments?
7
7
  #=> ["Banana", "Haddock!"]
8
8
  ```
9
9
 
10
- Well now it can!
10
+ Well now it can! Read on to see how to use it, or even better [read my post](https://www.sfcgeorge.co.uk/posts/2015/09/21/why-ruby-symbol-to-proc-works-and-more) explaining how it works with pictures.
11
+
11
12
 
12
13
  ## Methods
13
14
 
@@ -35,6 +36,16 @@ Yep, pass whatever arguments you like to your symbol method, very convenient!
35
36
  Note the dot before the brackets, it's short for `.call()` which you can also use.
36
37
 
37
38
 
39
+ ### [] with arguments
40
+
41
+ This is just an alternate syntax for the above `call` option, specifically designed to make enumerable indexing a little nicer:
42
+
43
+ ```ruby
44
+ [{ thing: "banana" }, { thing: "hammock!" }].map &:[][:thing]
45
+ #=> ["banana", "hammock!"]
46
+ ```
47
+
48
+
38
49
  ### ~ method tilde
39
50
 
40
51
  Instead of the method being called on the yielded object, the object(s) is passed to the method. How often have you wanted to do this:
@@ -139,7 +150,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
139
150
 
140
151
  ## Contributing
141
152
 
142
- 1. Fork it ( https://github.com/[my-github-username]/fancy_to_proc/fork )
153
+ 1. Fork it ( https://github.com/sfcgeorge/fancy_to_proc/fork )
143
154
  2. Create your feature branch (`git checkout -b my-new-feature`)
144
155
  3. Commit your changes (`git commit -am 'Add some feature'`)
145
156
  4. Push to the branch (`git push origin my-new-feature`)
data/lib/fancy_to_proc.rb CHANGED
@@ -20,6 +20,10 @@ class Symbol
20
20
  def call(*defaults)
21
21
  proc { |*args| args.shift.__send__(self, *defaults) }
22
22
  end unless respond_to?(:call)
23
+
24
+ def [](*defaults)
25
+ call(*defaults)
26
+ end unless respond_to?(:[])
23
27
  end
24
28
 
25
29
  class Proc
@@ -1,3 +1,3 @@
1
1
  module FancyToProc
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fancy_to_proc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon George