fancy_to_proc 0.2.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2e9f8ba404259416d9fb95f02c7512ccb94cd65
4
- data.tar.gz: 23a91d26ea0d8074f16e4a273faa5a375862c1e6
3
+ metadata.gz: 5c6c587248ad21bf2748b2b41f0be82dccc75e1e
4
+ data.tar.gz: 39bce2ac0005f609016af55f1465b5dcace94a42
5
5
  SHA512:
6
- metadata.gz: 2df9d1cdbe3381826f2017dae3d5556a57e42777df7d5a036fa7bbcc23c9a777bfe7bfc978366c3c1f073e5225612805a560c3568b3e50afd6a46d206f5d44dd
7
- data.tar.gz: a801aefaa530c52fa47cb99b79c7cfa25630faa6cb733331e803525f19f1af2f62cb409e46caf458997e1ac83f7ab0d7ef6d1a56a3bbe5e28317eac3f33dab42
6
+ metadata.gz: 4652260c29264f999840bda0517dd89b1813ea1ee7ea8fb7daf352e5432815a5c6a72d3f1c3e96bcb5a1c92ecb58df13e0332cd81d6e15e88288b97e8937c7ea
7
+ data.tar.gz: 1e3822f3ebe1bb1c5a26cb3ba7f650d149cdb7d980c881c567222082bf64e68079f553e3040cf1ce5aaeff1a58ee55c9cfd105dc7f1bf5312123101e7e1a439e
data/README.md CHANGED
@@ -53,6 +53,19 @@ Note, this is the unary tilde, so while it comes before it is actually just a me
53
53
 
54
54
  I'm not sure how I feel about these methods. They have their uses and they're not _too_ crazy, but they're still a bit unintuitive and weird. As such I'm calling them experimental and may remove / change them. Feedback please! Also note that if you're already defining any of the methods in this gem then they won't be clobbered.
55
55
 
56
+
57
+ ### [] Array to proc
58
+
59
+ Invokes the square brackets element reference method on Array or Hash.
60
+
61
+ ```ruby
62
+ [["banana"], ["hammock"]].map &[0] # works on Array or Hash
63
+ [{ thing: "banana" }, { thing: "hammock" }].map &[:thing]
64
+
65
+ #=> ["banana", "hammock"]
66
+ ```
67
+
68
+
56
69
  ### | pipe argument (Symbol)
57
70
 
58
71
  Pass a single argument to a symbol method, slightly shorter than the above call brackets style. Specifically designed for this kind of case:
data/lib/fancy_to_proc.rb CHANGED
@@ -31,3 +31,9 @@ class Proc
31
31
  proc { |*args| other.to_proc.call call(*args) }
32
32
  end unless method_defined?(:&)
33
33
  end
34
+
35
+ class Array
36
+ def to_proc
37
+ proc { |args| args[*self] }
38
+ end unless method_defined?(:to_proc)
39
+ end
@@ -1,3 +1,3 @@
1
1
  module FancyToProc
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon George