fancy_to_proc 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -11
- data/lib/fancy_to_proc/version.rb +1 -1
- data/lib/fancy_to_proc.rb +6 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2e9f8ba404259416d9fb95f02c7512ccb94cd65
|
4
|
+
data.tar.gz: 23a91d26ea0d8074f16e4a273faa5a375862c1e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2df9d1cdbe3381826f2017dae3d5556a57e42777df7d5a036fa7bbcc23c9a777bfe7bfc978366c3c1f073e5225612805a560c3568b3e50afd6a46d206f5d44dd
|
7
|
+
data.tar.gz: a801aefaa530c52fa47cb99b79c7cfa25630faa6cb733331e803525f19f1af2f62cb409e46caf458997e1ac83f7ab0d7ef6d1a56a3bbe5e28317eac3f33dab42
|
data/README.md
CHANGED
@@ -33,17 +33,7 @@ Yep, pass whatever arguments you like to your symbol method, very convenient!
|
|
33
33
|
#=> ["banana", "haddock!"]
|
34
34
|
```
|
35
35
|
|
36
|
-
Note the dot before the brackets
|
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
|
-
```
|
36
|
+
Note the dot before the brackets; it's short for `.call()` which you can also use. Unlike in Proc we can't use square brackets for a call alias `[]` as this is used by Symbol for element referencing already.
|
47
37
|
|
48
38
|
|
49
39
|
### ~ method tilde
|
data/lib/fancy_to_proc.rb
CHANGED
@@ -7,31 +7,27 @@ end
|
|
7
7
|
class Symbol
|
8
8
|
def ~
|
9
9
|
method(self).to_proc
|
10
|
-
end unless
|
10
|
+
end unless method_defined?(:~)
|
11
11
|
|
12
12
|
def |(other)
|
13
13
|
proc { |*args| args.shift.__send__(self, other) }
|
14
|
-
end unless
|
14
|
+
end unless method_defined?(:|)
|
15
15
|
|
16
16
|
def &(other)
|
17
17
|
proc { |*args| other.to_proc.call to_proc.call(*args) }
|
18
|
-
end unless
|
18
|
+
end unless method_defined?(:&)
|
19
19
|
|
20
20
|
def call(*defaults)
|
21
21
|
proc { |*args| args.shift.__send__(self, *defaults) }
|
22
|
-
end unless
|
23
|
-
|
24
|
-
def [](*defaults)
|
25
|
-
call(*defaults)
|
26
|
-
end unless respond_to?(:[])
|
22
|
+
end unless method_defined?(:call)
|
27
23
|
end
|
28
24
|
|
29
25
|
class Proc
|
30
26
|
def |(other)
|
31
27
|
curry(2)[other]
|
32
|
-
end unless
|
28
|
+
end unless method_defined?(:|)
|
33
29
|
|
34
30
|
def &(other)
|
35
31
|
proc { |*args| other.to_proc.call call(*args) }
|
36
|
-
end unless
|
32
|
+
end unless method_defined?(:&)
|
37
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fancy_to_proc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon George
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|