mug 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mug/array/delete_all.rb +43 -0
- data/lib/mug/array.rb +1 -0
- data/lib/mug.rb +1 -0
- data/test/test-array-delete_all.rb +39 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8607d458014afe4661b3cd1f1cfc0fa87971047
|
4
|
+
data.tar.gz: 4d154a7385f638a161b1c074a0f6075fa891da49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45dea11f88053bcfba35a38c1fecf8f3f9b28c5651a34d9112dc3ed1db46c0d4b28faae74bdf1c34924a7aa1315e539851b5390044b4cefe0818fc45edf4f153
|
7
|
+
data.tar.gz: 9268e8c575aab051f3809de7bd55f1a454811e98771ac40fa1db549e57e141b8a9053788582e206482e4969e204f481d6e00430ecfa36bf29fa5bad17ed1bfd4
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
class Array
|
3
|
+
|
4
|
+
#
|
5
|
+
# Deletes every element of +self+ for which block evaluates to +true+.
|
6
|
+
#
|
7
|
+
# Returns an array of the deleted elements.
|
8
|
+
#
|
9
|
+
# If no block is given, an Enumerator is returned instead.
|
10
|
+
#
|
11
|
+
# See #delete_if, #reject!
|
12
|
+
#
|
13
|
+
def delete_all &block
|
14
|
+
return enum_for :delete_all unless block_given?
|
15
|
+
[].tap do |removed|
|
16
|
+
delete_if do |e|
|
17
|
+
if yield e
|
18
|
+
removed << e
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
=begin
|
28
|
+
Copyright (c) 2017, Matthew Kerwin <matthew@kerwin.net.au>
|
29
|
+
|
30
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
31
|
+
purpose with or without fee is hereby granted, provided that the above
|
32
|
+
copyright notice and this permission notice appear in all copies.
|
33
|
+
|
34
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
35
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
36
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
37
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
38
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
39
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
40
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
41
|
+
=end
|
42
|
+
|
43
|
+
|
data/lib/mug/array.rb
CHANGED
data/lib/mug.rb
CHANGED
@@ -3,6 +3,7 @@ require_relative 'mug/alias'
|
|
3
3
|
require_relative 'mug/and-or'
|
4
4
|
require_relative 'mug/any-and-all'
|
5
5
|
require_relative 'mug/apply'
|
6
|
+
require_relative 'mug/array/delete_all'
|
6
7
|
require_relative 'mug/array/extend'
|
7
8
|
require_relative 'mug/array/minus'
|
8
9
|
require_relative 'mug/array/samples'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$VERBOSE = true
|
3
|
+
|
4
|
+
ARRAY = proc { [1,2,3,4,5,6] }
|
5
|
+
EVEN = proc { |i| i % 2 == 0 }
|
6
|
+
E = [2,4,6]
|
7
|
+
O = [1,3,5]
|
8
|
+
|
9
|
+
require_relative '../lib/mug/array/delete_all'
|
10
|
+
class Test_array_delete_all < Test::Unit::TestCase
|
11
|
+
def test_delete_all__block
|
12
|
+
a = ARRAY.call
|
13
|
+
result = a.delete_all &EVEN
|
14
|
+
assert_equal( result, E )
|
15
|
+
assert_equal( a, O )
|
16
|
+
end
|
17
|
+
def test_delete_all__noblock
|
18
|
+
a = ARRAY.call
|
19
|
+
enum = a.delete_all
|
20
|
+
assert( enum.is_a? Enumerator )
|
21
|
+
|
22
|
+
result = enum.each &EVEN
|
23
|
+
assert_equal( result, E )
|
24
|
+
assert_equal( a, O )
|
25
|
+
end
|
26
|
+
def test_delete_all__all
|
27
|
+
a = E.dup
|
28
|
+
result = a.delete_all &EVEN
|
29
|
+
assert_equal( result, E )
|
30
|
+
assert( a.empty? )
|
31
|
+
end
|
32
|
+
def test_delete_all__none
|
33
|
+
a = O.dup
|
34
|
+
result = a.delete_all &EVEN
|
35
|
+
assert( result.empty? )
|
36
|
+
assert_equal( a, O )
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
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
|
+
version: 0.10.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: 2017-
|
11
|
+
date: 2017-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
== MUG: Matty's Ultimate Gem
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- lib/mug/any-and-all.rb
|
29
29
|
- lib/mug/apply.rb
|
30
30
|
- lib/mug/array.rb
|
31
|
+
- lib/mug/array/delete_all.rb
|
31
32
|
- lib/mug/array/extend.rb
|
32
33
|
- lib/mug/array/minus.rb
|
33
34
|
- lib/mug/array/samples.rb
|
@@ -64,6 +65,7 @@ files:
|
|
64
65
|
- test/test-and-or.rb
|
65
66
|
- test/test-any-and-all.rb
|
66
67
|
- test/test-apply.rb
|
68
|
+
- test/test-array-delete_all.rb
|
67
69
|
- test/test-array-extend.rb
|
68
70
|
- test/test-array-minus.rb
|
69
71
|
- test/test-array-samples.rb
|
@@ -115,6 +117,7 @@ specification_version: 4
|
|
115
117
|
summary: 'MUG: Matty''s Ultimate Gem'
|
116
118
|
test_files:
|
117
119
|
- test/test-clamp.rb
|
120
|
+
- test/test-array-delete_all.rb
|
118
121
|
- test/test-rexproc.rb
|
119
122
|
- test/test-tau.rb
|
120
123
|
- test/test-matchdata_each.rb
|