mug 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mug/and-or.rb +22 -1
- data/lib/mug/any-and-all.rb +1 -1
- data/test/test-and-or.rb +39 -0
- metadata +23 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50b01316cc71f852a0b9486ea5b1109af29c8ca3
|
4
|
+
data.tar.gz: 92aec72f54e066f73de67d743a29218029f1c872
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19fd297cf043985f9abd55bf7863dfa859744ee1acc7941673c2796b523e92e27c67e3fd563212c36f70913dc927a37a4b91765cb861f51e82627ed73cfe797a
|
7
|
+
data.tar.gz: d60fc6a2152527708ff79a297f1feb2e84a1842d0eeef0ac580d6a8ac67040506f4cbcd27c9f93df90dd6654ae4c8bd0436a094f41b07e9a57b602fa374c339b
|
data/lib/mug/and-or.rb
CHANGED
@@ -28,10 +28,31 @@ class Object
|
|
28
28
|
self || default
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Calls +block+ if +obj+ is truthy.
|
34
|
+
#
|
35
|
+
# Returns +obj+.
|
36
|
+
#
|
37
|
+
def and_then &block
|
38
|
+
yield self if self
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Calls +block+ is +obj+ is not falsey.
|
44
|
+
#
|
45
|
+
# Returns +obj+.
|
46
|
+
#
|
47
|
+
def or_then &block
|
48
|
+
yield self unless self
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
31
52
|
end
|
32
53
|
|
33
54
|
=begin
|
34
|
-
Copyright (c)
|
55
|
+
Copyright (c) 2017, Matthew Kerwin <matthew@kerwin.net.au>
|
35
56
|
|
36
57
|
Permission to use, copy, modify, and/or distribute this software for any
|
37
58
|
purpose with or without fee is hereby granted, provided that the above
|
data/lib/mug/any-and-all.rb
CHANGED
@@ -4,7 +4,7 @@ module Enumerable
|
|
4
4
|
#
|
5
5
|
# Passes each element of the collection to the given block. The method returns `true` if the
|
6
6
|
# block contains elements that never return `false` or `nil`. If the block is not given, Ruby
|
7
|
-
# adds an implicit block of `{ |obj| obj }` which will cause `
|
7
|
+
# adds an implicit block of `{ |obj| obj }` which will cause `any_and_all?` to return `true`
|
8
8
|
# when none of the collection members are `false` or `nil`.
|
9
9
|
#
|
10
10
|
def any_and_all? &block
|
data/test/test-and-or.rb
CHANGED
@@ -37,5 +37,44 @@ class Test_and_or < Test::Unit::TestCase
|
|
37
37
|
assert_equal( 'a1c', 'a1c'.or(''){|x|x =~ /\d/} )
|
38
38
|
end
|
39
39
|
|
40
|
+
|
41
|
+
def test_and_then
|
42
|
+
[
|
43
|
+
[true, true, true],
|
44
|
+
[1, true, 1],
|
45
|
+
['a', true, 'a'],
|
46
|
+
[false, false, -1],
|
47
|
+
[nil, false, -1],
|
48
|
+
].each do |o,x,y|
|
49
|
+
v = false
|
50
|
+
r = o.and_then { v = true }
|
51
|
+
assert_equal( x, v ) # executes the block if truthy
|
52
|
+
assert_equal( o, r ) # returns self
|
53
|
+
|
54
|
+
v = -1
|
55
|
+
o.and_then {|e| v = e }
|
56
|
+
assert_equal( y, v ) # yields self
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_or_then
|
61
|
+
[
|
62
|
+
[true, false, -1],
|
63
|
+
[1, false, -1],
|
64
|
+
['a', false, -1],
|
65
|
+
[false, true, false],
|
66
|
+
[nil, true, nil],
|
67
|
+
].each do |o,x,y|
|
68
|
+
v = false
|
69
|
+
r = o.or_then { v = true }
|
70
|
+
assert_equal( x, v ) # executes the block if falsey
|
71
|
+
assert_equal( o, r ) # returns self
|
72
|
+
|
73
|
+
v = -1
|
74
|
+
o.or_then {|e| v = e }
|
75
|
+
assert_equal( y, v ) # yields self
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
40
79
|
end
|
41
80
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Kerwin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
== MUG: Matty's Ultimate Gem
|
@@ -105,35 +105,35 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.6.
|
108
|
+
rubygems_version: 2.6.2
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: 'MUG: Matty''s Ultimate Gem'
|
112
112
|
test_files:
|
113
|
-
- test/test-
|
113
|
+
- test/test-fragile-method-chain.rb
|
114
|
+
- test/test-maybe.rb
|
115
|
+
- test/test-hashop.rb
|
116
|
+
- test/test-not.rb
|
117
|
+
- test/test-loop-with.rb
|
118
|
+
- test/test-counts.rb
|
119
|
+
- test/test-array-minus.rb
|
120
|
+
- test/test-bool.rb
|
114
121
|
- test/test-rexproc.rb
|
122
|
+
- test/test-hashmerge.rb
|
123
|
+
- test/test-array-samples.rb
|
115
124
|
- test/test-tau.rb
|
116
|
-
- test/test-
|
125
|
+
- test/test-apply.rb
|
126
|
+
- test/test-any-and-all.rb
|
127
|
+
- test/test-clamp.rb
|
128
|
+
- test/test-iterator-for.rb
|
117
129
|
- test/test-bittest.rb
|
130
|
+
- test/test-negativity.rb
|
118
131
|
- test/test-matchdata_hash.rb
|
119
|
-
- test/test-not.rb
|
120
|
-
- test/test-array-extend.rb
|
121
|
-
- test/test-iterator-for.rb
|
122
|
-
- test/test-top.rb
|
123
|
-
- test/test-and-or.rb
|
124
|
-
- test/test-hashmerge.rb
|
125
|
-
- test/test-any-and-all.rb
|
126
132
|
- test/test-self.rb
|
127
|
-
- test/test-
|
128
|
-
- test/test-counts.rb
|
129
|
-
- test/test-negativity.rb
|
130
|
-
- test/test-bool.rb
|
133
|
+
- test/test-and-or.rb
|
131
134
|
- test/test-hashmap.rb
|
132
|
-
- test/test-
|
133
|
-
- test/test-
|
134
|
-
- test/test-array-samples.rb
|
135
|
-
- test/test-hashop.rb
|
135
|
+
- test/test-time.rb
|
136
|
+
- test/test-matchdata_each.rb
|
136
137
|
- test/test-iterator-method.rb
|
137
|
-
- test/test-
|
138
|
-
- test/test-
|
139
|
-
- test/test-fragile-method-chain.rb
|
138
|
+
- test/test-array-extend.rb
|
139
|
+
- test/test-top.rb
|