mug 0.4.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1d1008a00d350eb456faeba3099fa1f4ef91319
4
- data.tar.gz: a9acb854fcfb95e52f3b057524ee55113c5c424a
3
+ metadata.gz: dbc9df2427fedefa9ed326ebaa85af9f94055a20
4
+ data.tar.gz: 92a464c5eff53dbef69f098f176f4c67fdccf930
5
5
  SHA512:
6
- metadata.gz: 1811cbb8b2476aaf45d4d79535788da251b1da359d908d8893e42aae36a68f54807ddbf64794c2704b0ef1560411bd0e1cb55b9beb128ab8bfa9f4bdfc64379c
7
- data.tar.gz: 0263bd5cf6aa93bcc181684a8a7b7f1b21fbaede2c1d46de2c015d7064bac723e54ba0a6bbf9a01472d6b4b61fa3b688304de6cd374e6c63e430a20d66779bf9
6
+ metadata.gz: bd5bd64b1442ca799327f41b8e5325d32593c8762448254da80ef9d32f55b2ba92d97de4da152150ce6ee6854a99f5c7fad545017ec542698075a31a111993c9
7
+ data.tar.gz: 71d71d48de44e8074c336f258a55e8e1ae957f4204a6c12f1b6c1ab8361d9cca2676474a349ce2a1e8978cbd4283609469bd555fffd32441587a1cf54177b9f1
data/lib/mug.rb CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
2
  require_relative 'mug/and-or'
3
+ require_relative 'mug/any-and-all'
3
4
  require_relative 'mug/apply'
4
5
  require_relative 'mug/array/extend'
5
6
  require_relative 'mug/array/minus'
@@ -16,6 +17,7 @@ require_relative 'mug/matchdata/each'
16
17
  require_relative 'mug/matchdata/hash'
17
18
  require_relative 'mug/maybe'
18
19
  require_relative 'mug/negativity'
20
+ require_relative 'mug/nonempty'
19
21
  require_relative 'mug/rexproc'
20
22
  require_relative 'mug/self'
21
23
  require_relative 'mug/tau'
@@ -0,0 +1,38 @@
1
+
2
+ module Enumerable
3
+
4
+ #
5
+ # Passes each element of the collection to the given block. The method returns `true` if the
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 `and_and_all?` to return `true`
8
+ # when none of the collection members are `false` or `nil`.
9
+ #
10
+ def any_and_all? &block
11
+ block ||= proc {|obj| obj }
12
+
13
+ result = false
14
+ each do |x|
15
+ return false unless block[x]
16
+ result = true
17
+ end
18
+ result
19
+ end
20
+
21
+ end
22
+
23
+ =begin
24
+ Copyright (c) 2016, 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
38
+
@@ -0,0 +1,71 @@
1
+
2
+ class Array
3
+ #
4
+ # Returns +true+ if +self+ contains elements.
5
+ #
6
+ def nonempty?
7
+ !empty?
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?
53
+ end
54
+ end
55
+
56
+ =begin
57
+ Copyright (c) 2016, Matthew Kerwin <matthew@kerwin.net.au>
58
+
59
+ Permission to use, copy, modify, and/or distribute this software for any
60
+ purpose with or without fee is hereby granted, provided that the above
61
+ copyright notice and this permission notice appear in all copies.
62
+
63
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
64
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
65
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
66
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
67
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
68
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
69
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
70
+ =end
71
+
@@ -0,0 +1,25 @@
1
+ require 'test/unit'
2
+ $VERBOSE = true
3
+
4
+ require_relative '../lib/mug/any-and-all'
5
+ class Test_any_and_all < Test::Unit::TestCase
6
+ def test_any_and_all__block
7
+ b = proc {|o| o > 1 }
8
+ [
9
+ [ false, [] ],
10
+ [ false, [3,0,9] ],
11
+ [ true, [3,5,9] ],
12
+ ].each do |x, a|
13
+ assert_equal( x, a.any_and_all?(&b) )
14
+ end
15
+ end
16
+ def test_any_and_all__noblock
17
+ [
18
+ [ false, [] ],
19
+ [ false, [3,nil,9] ],
20
+ [ true, [3,5,9] ],
21
+ ].each do |x, a|
22
+ assert_equal( x, a.any_and_all? )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
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
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.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Kerwin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  == MUG: Matty's Ultimate Gem
@@ -24,6 +24,7 @@ extra_rdoc_files: []
24
24
  files:
25
25
  - lib/mug.rb
26
26
  - lib/mug/and-or.rb
27
+ - lib/mug/any-and-all.rb
27
28
  - lib/mug/apply.rb
28
29
  - lib/mug/array.rb
29
30
  - lib/mug/array/extend.rb
@@ -47,12 +48,14 @@ files:
47
48
  - lib/mug/matchdata/hash.rb
48
49
  - lib/mug/maybe.rb
49
50
  - lib/mug/negativity.rb
51
+ - lib/mug/nonempty.rb
50
52
  - lib/mug/rexproc.rb
51
53
  - lib/mug/self.rb
52
54
  - lib/mug/tau.rb
53
55
  - lib/mug/to_h.rb
54
56
  - lib/mug/top.rb
55
57
  - test/test-and-or.rb
58
+ - test/test-any-and-all.rb
56
59
  - test/test-apply.rb
57
60
  - test/test-array-extend.rb
58
61
  - test/test-array-minus.rb
@@ -69,6 +72,7 @@ files:
69
72
  - test/test-matchdata_hash.rb
70
73
  - test/test-maybe.rb
71
74
  - test/test-negativity.rb
75
+ - test/test-nonempty.rb
72
76
  - test/test-rexproc.rb
73
77
  - test/test-self.rb
74
78
  - test/test-tau.rb
@@ -93,29 +97,31 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
97
  version: '0'
94
98
  requirements: []
95
99
  rubyforge_project:
96
- rubygems_version: 2.4.5
100
+ rubygems_version: 2.5.1
97
101
  signing_key:
98
102
  specification_version: 4
99
103
  summary: 'MUG: Matty''s Ultimate Gem'
100
104
  test_files:
101
- - test/test-fragile-method-chain.rb
102
- - test/test-maybe.rb
103
- - test/test-hashop.rb
104
- - test/test-loop-with.rb
105
- - test/test-counts.rb
106
- - test/test-array-minus.rb
107
- - test/test-bool.rb
105
+ - test/test-clamp.rb
108
106
  - test/test-rexproc.rb
109
107
  - test/test-tau.rb
110
- - test/test-apply.rb
111
- - test/test-clamp.rb
112
- - test/test-iterator-for.rb
113
- - test/test-negativity.rb
108
+ - test/test-nonempty.rb
109
+ - test/test-matchdata_each.rb
114
110
  - test/test-matchdata_hash.rb
115
- - test/test-self.rb
111
+ - test/test-array-extend.rb
112
+ - test/test-iterator-for.rb
113
+ - test/test-top.rb
116
114
  - test/test-and-or.rb
115
+ - test/test-any-and-all.rb
116
+ - test/test-self.rb
117
+ - test/test-counts.rb
118
+ - test/test-negativity.rb
119
+ - test/test-bool.rb
117
120
  - test/test-hashmap.rb
118
- - test/test-matchdata_each.rb
121
+ - test/test-loop-with.rb
122
+ - test/test-maybe.rb
123
+ - test/test-hashop.rb
119
124
  - test/test-iterator-method.rb
120
- - test/test-array-extend.rb
121
- - test/test-top.rb
125
+ - test/test-apply.rb
126
+ - test/test-array-minus.rb
127
+ - test/test-fragile-method-chain.rb