fancy_to_proc 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -7
- data/lib/fancy_to_proc.rb +10 -0
- data/lib/fancy_to_proc/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 784d44c460fa5c95785aa81007bdbeb80d7a7b24
|
4
|
+
data.tar.gz: b66c74bab9bcc48eeb6656d055b865de65fc0d0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5891315a6b5097da487f6eab4545c67bbeef8ca80756a1b4aa24c6d19a1973892d9e80d6d51591a8e9b197573bda96419b5f91d43704101d8b0375d636b53575
|
7
|
+
data.tar.gz: 76cec40169bb4d12f3c8e18845105e434071ec73859a9c94caeadee4403b853d20e197d2cda0100642cfa9fb0f048c489af4a8a7840d4c78e997a2c14c52b8eb
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Well now it can! Read on to see how to use it, or even better [read my post](htt
|
|
14
14
|
|
15
15
|
### & chainable ampersand
|
16
16
|
|
17
|
-
The ampersand operator is added to Symbol
|
17
|
+
The ampersand operator is added to Symbol, Proc and Method so that you can chain like so:
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
["banana", " hammock! "].map &:strip&:capitalize
|
@@ -23,6 +23,15 @@ The ampersand operator is added to Symbol (and Proc) so that you can chain like
|
|
23
23
|
|
24
24
|
Note that above the first ampersand is built into Ruby, it's the second ampersand added by this Gem.
|
25
25
|
|
26
|
+
You can also use the `method` method to get a method and use that as a proc in a chain...
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
["banana", "hammock"].map &method(:p)&:upcase
|
30
|
+
#-> "banana"
|
31
|
+
#-> "hammock"
|
32
|
+
#=> ["BANANA", "HADDOCK"]
|
33
|
+
```
|
34
|
+
|
26
35
|
|
27
36
|
### .() call with arguments
|
28
37
|
|
@@ -36,6 +45,11 @@ Yep, pass whatever arguments you like to your symbol method, very convenient!
|
|
36
45
|
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.
|
37
46
|
|
38
47
|
|
48
|
+
## Experimental!
|
49
|
+
|
50
|
+
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.
|
51
|
+
|
52
|
+
|
39
53
|
### ~ method tilde
|
40
54
|
|
41
55
|
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:
|
@@ -46,12 +60,7 @@ Instead of the method being called on the yielded object, the object(s) is passe
|
|
46
60
|
#=> "scrunchie"
|
47
61
|
```
|
48
62
|
|
49
|
-
Note
|
50
|
-
|
51
|
-
|
52
|
-
## Experimental!
|
53
|
-
|
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.
|
63
|
+
Note; this is the unary tilde, so while it comes before it's just a method called on Symbol. It can only look up methods on Symbol but that includes things from Kernel like `p` and `puts`, but it's otherwise limited. Also due to operator precedence it needs wrapping in brackets if you want to chain.
|
55
64
|
|
56
65
|
|
57
66
|
### [] Array to proc
|
@@ -145,12 +154,14 @@ Or to use on the command line require it with a flag:
|
|
145
154
|
rubocop --require fancy_to_proc
|
146
155
|
```
|
147
156
|
|
157
|
+
|
148
158
|
## Development
|
149
159
|
|
150
160
|
Run `bin/console` for an interactive prompt that will allow you to experiment.
|
151
161
|
|
152
162
|
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
153
163
|
|
164
|
+
|
154
165
|
## Contributing
|
155
166
|
|
156
167
|
1. Fork it ( https://github.com/sfcgeorge/fancy_to_proc/fork )
|
data/lib/fancy_to_proc.rb
CHANGED
@@ -36,6 +36,16 @@ class Proc
|
|
36
36
|
end unless method_defined?(:&)
|
37
37
|
end
|
38
38
|
|
39
|
+
class Method
|
40
|
+
def |(other)
|
41
|
+
curry(2)[other]
|
42
|
+
end unless method_defined?(:|)
|
43
|
+
|
44
|
+
def &(other)
|
45
|
+
proc { |*args| other.to_proc.call call(*args) }
|
46
|
+
end unless method_defined?(:&)
|
47
|
+
end
|
48
|
+
|
39
49
|
class Array
|
40
50
|
def to_proc
|
41
51
|
proc { |args| args[*self] }
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon George
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,4 +97,3 @@ signing_key:
|
|
97
97
|
specification_version: 4
|
98
98
|
summary: Makes Symbol#to_proc chainable and take arguments
|
99
99
|
test_files: []
|
100
|
-
has_rdoc:
|