apply 1.0.1 → 1.0.2
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 +4 -4
- data/README.md +4 -6
- data/lib/apply.rb +2 -2
- data/lib/apply/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a867fc3c245f700fd6af6b14d3b10ba1771134f9
|
4
|
+
data.tar.gz: 4549f1cd24fb22b068640650e807f073c38ed3c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 341cc4bb04771c5e001ddfd557e1b7bec3b3af8a9cdbad1efa24a5d083a152d46193ee8736df2ea530b6479b9f9426067e8d8fe5e96eb48ea86eb4ef809e9978
|
7
|
+
data.tar.gz: afdf4b37468264e14b061723d4c1de79e220939fe63bcc329b693b0d74bbd1342ad26634026acf68b43775861126670beb3c035291f6b0782852a0674fcd0b0b
|
data/README.md
CHANGED
@@ -13,14 +13,12 @@ passed to the proc. If the condition is false, the argument is returned immediat
|
|
13
13
|
require "apply"
|
14
14
|
|
15
15
|
# Upcase strings that start with a lowercase letter
|
16
|
-
|
17
|
-
|
18
|
-
%w{ Alice bob Carol }.map(&upcaser) # => [ "Alice", "BOB", "Carol" ]
|
16
|
+
upcase_if_starts_with_lowercase = Apply(&:upcase).if { |value| value =~ /^[a-z]/ }
|
17
|
+
%w{ Alice bob Carol }.map(&upcase_if_starts_with_lowercase) # => [ "Alice", "BOB", "Carol" ]
|
19
18
|
|
20
19
|
# Parenthesize non-nil values
|
21
|
-
|
22
|
-
|
23
|
-
[ "Alice", nil, "Carol" ].map(&parenthesizer) # => [ "(Alice)", nil, "(Bob)" ]
|
20
|
+
parenthesize_unless_nil = Apply { |text| "(#{text})" }.unless(&:nil?)
|
21
|
+
[ "Alice", nil, "Carol" ].map(&parenthesize_unless_nil) # => [ "(Alice)", nil, "(Bob)" ]
|
24
22
|
|
25
23
|
```
|
26
24
|
|
data/lib/apply.rb
CHANGED
@@ -2,11 +2,11 @@ require "apply/version"
|
|
2
2
|
|
3
3
|
module Apply
|
4
4
|
def if(&test)
|
5
|
-
|
5
|
+
->(value) { test[value] ? call(value) : value }
|
6
6
|
end
|
7
7
|
|
8
8
|
def unless(&test)
|
9
|
-
|
9
|
+
->(value) { test[value] ? value : call(value) }
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
data/lib/apply/version.rb
CHANGED