bendy 0.2.2 → 0.2.3
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/lib/bendy/array.rb +3 -3
- data/lib/bendy/logical.rb +11 -5
- data/lib/bendy/object.rb +9 -5
- data/lib/bendy/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: 112813b4db4e44430d77d0e63ffc665af0631cb5
|
4
|
+
data.tar.gz: 375b6985f76d99f0f9fd6f9603caff68fe8eca40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e94fbb1e395310ff7083209d1d907dacd742c98b9e81e776ffef2eb0a8d02068e4982172b68f635d0eacda976b91d9771d7803fbf82c4e6015853b5b38296ae6
|
7
|
+
data.tar.gz: 9c2eb3ae3d6903c07fd1ae7ca56c4b9607cebed81f09150a0577899bebc09eb3ab60b521092add1d989b0a6d8e7dd73576722a9f471113558dad64f76eea8c1f
|
data/lib/bendy/array.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
##
|
2
|
-
# We're using refinements to
|
2
|
+
# We're using refinements to _freedom patch_ Array in a safe way.
|
3
3
|
|
4
4
|
module Bendy
|
5
5
|
|
@@ -7,7 +7,7 @@ module Bendy
|
|
7
7
|
refine Array do
|
8
8
|
|
9
9
|
##
|
10
|
-
#
|
10
|
+
# +tails+ produces all sub-arrays by successively dropping leading
|
11
11
|
# elements:
|
12
12
|
#
|
13
13
|
# [1, 2, 3].tails
|
@@ -18,7 +18,7 @@ module Bendy
|
|
18
18
|
end
|
19
19
|
|
20
20
|
##
|
21
|
-
#
|
21
|
+
# +inits+ produces all sub-arrays by successively taking leading
|
22
22
|
# elements:
|
23
23
|
#
|
24
24
|
# [1, 2, 3].tails
|
data/lib/bendy/logical.rb
CHANGED
@@ -6,13 +6,19 @@ module Bendy
|
|
6
6
|
module Logical
|
7
7
|
|
8
8
|
##
|
9
|
+
# call-seq:
|
10
|
+
# implies(antecedent) { consequent } #=> true or consequent
|
11
|
+
#
|
9
12
|
# Material implication
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
+
#
|
14
|
+
# +implies+ is the common case where if the first thing is true
|
15
|
+
# (antecedent), then pay attention to the second thing (consequent). But
|
16
|
+
# if the first thing is false then the whole thing is true:
|
17
|
+
#
|
18
|
+
# implies(foo){foo[:bar]}
|
13
19
|
|
14
|
-
def implies(
|
15
|
-
!!
|
20
|
+
def implies(antecedent)
|
21
|
+
!!antecedent ? yield : true
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
data/lib/bendy/object.rb
CHANGED
@@ -2,13 +2,17 @@ module Bendy
|
|
2
2
|
refine Object do
|
3
3
|
|
4
4
|
##
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# call-seq:
|
6
|
+
# try(:some_method) #=> result of method or nil
|
7
7
|
#
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# +try+ acts like a normal method call, unless it is being called
|
9
|
+
# on a +nil+ object, in which case it returns +nil+:
|
10
10
|
#
|
11
|
-
#
|
11
|
+
# nil.try(:to_i) # => nil
|
12
|
+
# "10".try(:to_i) # => 10
|
13
|
+
#
|
14
|
+
# Copied pretty much verbatim from ActiveSupport:
|
15
|
+
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/try.rb
|
12
16
|
|
13
17
|
def try(*a, &b)
|
14
18
|
if a.empty? && block_given?
|
data/lib/bendy/version.rb
CHANGED