mug 0.4.2 → 0.5
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 -1
- data/lib/mug/{nonempty.rb → not.rb} +10 -49
- data/test/test-not.rb +60 -0
- metadata +4 -4
- data/test/test-nonempty.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 312309b5648e3c0bcf0f20a78b1f2e8967a8c407
|
4
|
+
data.tar.gz: 36928e26dc4bbc52d6f4a8ef58a6a8faca5f6879
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8728a0f1d3fdfaf985ba2ef0201d0895e0ac47963c214ca45713bb11526fbcd6622e3f712ab58ae4a32dc98596220981c898ad43391d1cd152c8aee56a720c3b
|
7
|
+
data.tar.gz: 4d347c516b264cffc9da8b80b19f168d0a1946db18df8f74c76a1443dc39876b1e7d69249ccd557fa5da494f89af81658d268d7277862f5860b8e8d9495d122e
|
data/lib/mug.rb
CHANGED
@@ -17,7 +17,7 @@ require_relative 'mug/matchdata/each'
|
|
17
17
|
require_relative 'mug/matchdata/hash'
|
18
18
|
require_relative 'mug/maybe'
|
19
19
|
require_relative 'mug/negativity'
|
20
|
-
require_relative 'mug/
|
20
|
+
require_relative 'mug/not'
|
21
21
|
require_relative 'mug/rexproc'
|
22
22
|
require_relative 'mug/self'
|
23
23
|
require_relative 'mug/tau'
|
@@ -1,55 +1,10 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
module Kernel
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# Negate a predicate.
|
5
5
|
#
|
6
|
-
def
|
7
|
-
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Hash
|
12
|
-
#
|
13
|
-
# Returns +true+ if +hsh+ contains elements.
|
14
|
-
#
|
15
|
-
def nonempty?
|
16
|
-
!empty?
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class String
|
21
|
-
#
|
22
|
-
# Returns +true+ if +str+ has a length greater than zero.
|
23
|
-
#
|
24
|
-
def nonempty?
|
25
|
-
!empty?
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class Symbol
|
30
|
-
#
|
31
|
-
# Returns that +sym+ is not :"".
|
32
|
-
#
|
33
|
-
def nonempty?
|
34
|
-
!empty?
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class << ENV
|
39
|
-
#
|
40
|
-
# Returns true when there are environment variables.
|
41
|
-
#
|
42
|
-
def nonempty?
|
43
|
-
!empty?
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class Queue
|
48
|
-
#
|
49
|
-
# Returns +true+ if the queue is not empty.
|
50
|
-
#
|
51
|
-
def nonempty?
|
52
|
-
!empty?
|
6
|
+
def not(*a, &b)
|
7
|
+
not a.empty? ? (b ? (yield self) : self) : __send__(*a, &b)
|
53
8
|
end
|
54
9
|
end
|
55
10
|
|
@@ -60,6 +15,12 @@ Permission to use, copy, modify, and/or distribute this software for any
|
|
60
15
|
purpose with or without fee is hereby granted, provided that the above
|
61
16
|
copyright notice and this permission notice appear in all copies.
|
62
17
|
|
18
|
+
Additional license is granted to the Ruby Core Team to use this software
|
19
|
+
in the ruby core or ruby standard libraries without including the above
|
20
|
+
copyright notice nor this permission notice. Subsequently, such a copy
|
21
|
+
of this software becomes wholly subject to the relevant licensing terms
|
22
|
+
of the ruby core or ruby standard libraries.
|
23
|
+
|
63
24
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
64
25
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
65
26
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
data/test/test-not.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$VERBOSE = true
|
3
|
+
|
4
|
+
require_relative '../lib/mug/not'
|
5
|
+
class Test_not < Test::Unit::TestCase
|
6
|
+
def test_not__noargs
|
7
|
+
[
|
8
|
+
[true, false],
|
9
|
+
[99, false],
|
10
|
+
[false, true],
|
11
|
+
[nil, true],
|
12
|
+
].each do |o, x|
|
13
|
+
assert_equal( x, o.not, "#{o.inspect}.not should be #{x}" )
|
14
|
+
end
|
15
|
+
end
|
16
|
+
def test_not__method
|
17
|
+
[
|
18
|
+
[[], false],
|
19
|
+
[[99], true],
|
20
|
+
].each do |o, x|
|
21
|
+
assert_equal( x, o.not(:empty?), "#{o.inspect}.not(:empty?) should be #{x}" )
|
22
|
+
end
|
23
|
+
end
|
24
|
+
def test_not__method2
|
25
|
+
[
|
26
|
+
[[], false],
|
27
|
+
[[99], true],
|
28
|
+
].each do |o, x|
|
29
|
+
assert_equal( x, o.not(&:empty?), "#{o.inspect}.not(&:empty?) should be #{x}" )
|
30
|
+
end
|
31
|
+
end
|
32
|
+
def test_not__args
|
33
|
+
[
|
34
|
+
[1, true],
|
35
|
+
[0, true],
|
36
|
+
[-1, false],
|
37
|
+
].each do |o, x|
|
38
|
+
assert_equal( x, o.not(:<, 0), "#{o.inspect}.not(:<, 0) should be #{x}" )
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_not__block
|
43
|
+
[
|
44
|
+
[1, true],
|
45
|
+
[0, true],
|
46
|
+
[-1, false],
|
47
|
+
].each do |o, x|
|
48
|
+
assert_equal( x, o.not {|obj| obj < 0 }, "#{o.inspect}.not{|obj|obj<0} should be #{x}" )
|
49
|
+
end
|
50
|
+
end
|
51
|
+
def test_not__method_block
|
52
|
+
[
|
53
|
+
[[], true],
|
54
|
+
[[0,-1], true],
|
55
|
+
[[0,99], false],
|
56
|
+
].each do |o, x|
|
57
|
+
assert_equal( x, o.not(:any?) {|item| item > 0 }, "#{o.inspect}.not(:any?){|item|item>0} should be #{x}" )
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Kerwin
|
@@ -48,7 +48,7 @@ files:
|
|
48
48
|
- lib/mug/matchdata/hash.rb
|
49
49
|
- lib/mug/maybe.rb
|
50
50
|
- lib/mug/negativity.rb
|
51
|
-
- lib/mug/
|
51
|
+
- lib/mug/not.rb
|
52
52
|
- lib/mug/rexproc.rb
|
53
53
|
- lib/mug/self.rb
|
54
54
|
- lib/mug/tau.rb
|
@@ -72,7 +72,7 @@ files:
|
|
72
72
|
- test/test-matchdata_hash.rb
|
73
73
|
- test/test-maybe.rb
|
74
74
|
- test/test-negativity.rb
|
75
|
-
- test/test-
|
75
|
+
- test/test-not.rb
|
76
76
|
- test/test-rexproc.rb
|
77
77
|
- test/test-self.rb
|
78
78
|
- test/test-tau.rb
|
@@ -105,9 +105,9 @@ test_files:
|
|
105
105
|
- test/test-clamp.rb
|
106
106
|
- test/test-rexproc.rb
|
107
107
|
- test/test-tau.rb
|
108
|
-
- test/test-nonempty.rb
|
109
108
|
- test/test-matchdata_each.rb
|
110
109
|
- test/test-matchdata_hash.rb
|
110
|
+
- test/test-not.rb
|
111
111
|
- test/test-array-extend.rb
|
112
112
|
- test/test-iterator-for.rb
|
113
113
|
- test/test-top.rb
|
data/test/test-nonempty.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
$VERBOSE = true
|
3
|
-
|
4
|
-
require_relative '../lib/mug/nonempty'
|
5
|
-
require 'thread'
|
6
|
-
class Test_nonempty < Test::Unit::TestCase
|
7
|
-
def test_nonempty
|
8
|
-
yes = [
|
9
|
-
[nil],
|
10
|
-
{ :foo => nil },
|
11
|
-
Queue.new.tap{|q| q << 1 },
|
12
|
-
'x',
|
13
|
-
:x,
|
14
|
-
]
|
15
|
-
no = [
|
16
|
-
[],
|
17
|
-
{},
|
18
|
-
Queue.new,
|
19
|
-
'',
|
20
|
-
:'',
|
21
|
-
]
|
22
|
-
yes.each do |obj|
|
23
|
-
assert( obj.nonempty?, "#{obj.inspect} should be nonempty?" )
|
24
|
-
end
|
25
|
-
no.each do |obj|
|
26
|
-
assert( !obj.nonempty?, "#{obj.inspect} should not be nonempty?" )
|
27
|
-
end
|
28
|
-
assert_raise( NoMethodError ) { Object.new.nonempty? }
|
29
|
-
end
|
30
|
-
end
|