mug 1.0.0 → 1.1.0
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/mug.rb +1 -0
- data/lib/mug/iff.rb +37 -0
- data/test/test-iff.rb +54 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 330eebe01439970eeb98b02f25580aa4b33335c3a3d7abe0994c378c8171d5eb
|
4
|
+
data.tar.gz: aaa14057580d8ed7a51a575c9eb8820de6a9507724ad953791e596a3a96fd3d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea3615b7990f7bfd2505985c3ae8ecea789390904fb4a136973c3e211c764a32861c4d2dfb8b1691b4c64ac09fcc184b902a612f6d988cab61c0137724d019d2
|
7
|
+
data.tar.gz: 295e43e6f35e73a2b7cf2fe79dc99466ddd4f0624c1c83f400e5bdbe6665a3ff99559a367bcf9ea3e8d771689c6c0161fc1d533988baceb255212f3520d96166
|
data/lib/mug.rb
CHANGED
@@ -17,6 +17,7 @@ require_relative 'mug/hash/map'
|
|
17
17
|
require_relative 'mug/hash/merge'
|
18
18
|
require_relative 'mug/hash/operations'
|
19
19
|
require_relative 'mug/hash/when'
|
20
|
+
require_relative 'mug/iff'
|
20
21
|
require_relative 'mug/iterator'
|
21
22
|
require_relative 'mug/iterator/for'
|
22
23
|
require_relative 'mug/iterator/method'
|
data/lib/mug/iff.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
class Object
|
3
|
+
|
4
|
+
##
|
5
|
+
# Test for logical equivalence.
|
6
|
+
#
|
7
|
+
# Returns true if +condition+ and +obj+ are either
|
8
|
+
# both truthy, or both falsey.
|
9
|
+
#
|
10
|
+
def iff? *condition
|
11
|
+
if condition.length == 1
|
12
|
+
cond = condition[0]
|
13
|
+
elsif condition.empty? && block_given?
|
14
|
+
cond = yield
|
15
|
+
else
|
16
|
+
raise ArgumentError, "wrong number of arguments (given #{condition.length}, expected 1)"
|
17
|
+
end
|
18
|
+
cond ? !!self : !self
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
=begin
|
24
|
+
Copyright (c) 2018, Matthew Kerwin <matthew@kerwin.net.au>
|
25
|
+
|
26
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
27
|
+
purpose with or without fee is hereby granted, provided that the above
|
28
|
+
copyright notice and this permission notice appear in all copies.
|
29
|
+
|
30
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
31
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
32
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
33
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
34
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
35
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
36
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
37
|
+
=end
|
data/test/test-iff.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$VERBOSE = true
|
3
|
+
|
4
|
+
require_relative '../lib/mug/iff'
|
5
|
+
class Test_iff < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_iff
|
8
|
+
truthy = [true, 1, Object.new]
|
9
|
+
falsey = [false, nil]
|
10
|
+
|
11
|
+
truthy.each do |cond|
|
12
|
+
truthy.each do |obj|
|
13
|
+
assert( obj.iff?(cond) )
|
14
|
+
end
|
15
|
+
falsey.each do |obj|
|
16
|
+
assert( !( obj.iff?(cond) ) )
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
falsey.each do |cond|
|
21
|
+
truthy.each do |obj|
|
22
|
+
assert( !( obj.iff?(cond) ) )
|
23
|
+
end
|
24
|
+
falsey.each do |obj|
|
25
|
+
assert( obj.iff?(cond) )
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_iff_block
|
31
|
+
truthy = [true, 1, Object.new]
|
32
|
+
falsey = [false, nil]
|
33
|
+
|
34
|
+
truthy.each do |cond|
|
35
|
+
truthy.each do |obj|
|
36
|
+
assert( obj.iff? do cond; end )
|
37
|
+
end
|
38
|
+
falsey.each do |obj|
|
39
|
+
assert( !( obj.iff? do cond; end ) )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
falsey.each do |cond|
|
44
|
+
truthy.each do |obj|
|
45
|
+
assert( !( obj.iff? do cond; end ) )
|
46
|
+
end
|
47
|
+
falsey.each do |obj|
|
48
|
+
assert( obj.iff? do cond; end )
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
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: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Kerwin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
== MUG: Matty's Ultimate Gem
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/mug/hash/when.rb
|
51
51
|
- lib/mug/hashmap.rb
|
52
52
|
- lib/mug/hashop.rb
|
53
|
+
- lib/mug/iff.rb
|
53
54
|
- lib/mug/iterator.rb
|
54
55
|
- lib/mug/iterator/for.rb
|
55
56
|
- lib/mug/iterator/method.rb
|
@@ -88,6 +89,7 @@ files:
|
|
88
89
|
- test/test-hashmerge.rb
|
89
90
|
- test/test-hashop.rb
|
90
91
|
- test/test-hashwhen.rb
|
92
|
+
- test/test-iff.rb
|
91
93
|
- test/test-iterator-for.rb
|
92
94
|
- test/test-iterator-method.rb
|
93
95
|
- test/test-iterator.rb
|
@@ -134,6 +136,7 @@ test_files:
|
|
134
136
|
- test/test-loop-with.rb
|
135
137
|
- test/test-counts.rb
|
136
138
|
- test/test-array-minus.rb
|
139
|
+
- test/test-iff.rb
|
137
140
|
- test/test-affix.rb
|
138
141
|
- test/test-bool.rb
|
139
142
|
- test/test-alias.rb
|