mug 0.3.0 → 0.3.1
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/array/minus.rb +54 -0
- data/lib/mug/array.rb +1 -0
- data/lib/mug.rb +1 -0
- data/test/test-array-minus.rb +19 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d07407afa937cc922025564e10c1dfd2a16535f2
|
4
|
+
data.tar.gz: 0391bcb1f0b93e59e852cf3bc1ba8eee0bc95e9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f8cea3e467019cdb61879a1d8bb87770e88f1796f2db4a93b692e092b3352a58438d81044ee59d9f8730512a8a85a4120c6f48141ee54713067f38e7f57fcd2
|
7
|
+
data.tar.gz: d7b36788bd623f2528a59b50929a940327ee656dbb8ad8f57c3a500f3b20738c5c1e7529a257121d388b7ae1735bd91b1b27a6e1adff2a8963ecd18a5511f1a4
|
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
class Array
|
3
|
+
|
4
|
+
##
|
5
|
+
# Subtract elements from this array.
|
6
|
+
#
|
7
|
+
# This is similar to Array#- except that elements from this array are
|
8
|
+
# removed only once per instance in +ary+.
|
9
|
+
#
|
10
|
+
# If +remainder+ is given and true, returns a second array which is
|
11
|
+
# all elements in +ary+ that were not present in this array.
|
12
|
+
#
|
13
|
+
# @call-seq minus(ary)
|
14
|
+
# @call-seq minus(ary, remainder: true)
|
15
|
+
#
|
16
|
+
def minus ary, remainder: false
|
17
|
+
|
18
|
+
result = dup
|
19
|
+
rem = []
|
20
|
+
|
21
|
+
ary.each do |x|
|
22
|
+
i = result.index x
|
23
|
+
if i
|
24
|
+
result.delete_at i
|
25
|
+
elsif remainder
|
26
|
+
rem << x
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if remainder
|
31
|
+
[result, rem]
|
32
|
+
else
|
33
|
+
result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
=begin
|
40
|
+
Copyright (c) 2015, Matthew Kerwin <matthew@kerwin.net.au>
|
41
|
+
|
42
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
43
|
+
purpose with or without fee is hereby granted, provided that the above
|
44
|
+
copyright notice and this permission notice appear in all copies.
|
45
|
+
|
46
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
47
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
48
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
49
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
50
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
51
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
52
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
53
|
+
=end
|
54
|
+
|
data/lib/mug/array.rb
CHANGED
data/lib/mug.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$VERBOSE = true
|
3
|
+
|
4
|
+
require_relative '../lib/mug/array/minus'
|
5
|
+
class Test_array_minus < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_array_minus
|
8
|
+
a = %w[q q w e r e e ]
|
9
|
+
b = %w[q w e e t]
|
10
|
+
c = %w[ q r e ]
|
11
|
+
d = %w[ t]
|
12
|
+
assert_equal( c, a.minus(b) )
|
13
|
+
assert_equal( d, b.minus(a) )
|
14
|
+
assert_equal( c, a.minus(b, remainder: false) )
|
15
|
+
assert_equal( [c,d], a.minus(b, remainder: true ) )
|
16
|
+
assert_equal( [d,c], b.minus(a, remainder: true ) )
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Kerwin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
== MUG: Matty's Ultimate Gem
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- lib/mug/apply.rb
|
28
28
|
- lib/mug/array.rb
|
29
29
|
- lib/mug/array/extend.rb
|
30
|
+
- lib/mug/array/minus.rb
|
30
31
|
- lib/mug/bool.rb
|
31
32
|
- lib/mug/clamp.rb
|
32
33
|
- lib/mug/counts.rb
|
@@ -51,6 +52,7 @@ files:
|
|
51
52
|
- test/test-and-or.rb
|
52
53
|
- test/test-apply.rb
|
53
54
|
- test/test-array-extend.rb
|
55
|
+
- test/test-array-minus.rb
|
54
56
|
- test/test-bool.rb
|
55
57
|
- test/test-clamp.rb
|
56
58
|
- test/test-counts.rb
|
@@ -86,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
88
|
version: '0'
|
87
89
|
requirements: []
|
88
90
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.5
|
91
|
+
rubygems_version: 2.4.5
|
90
92
|
signing_key:
|
91
93
|
specification_version: 4
|
92
94
|
summary: 'MUG: Matty''s Ultimate Gem'
|
@@ -108,4 +110,5 @@ test_files:
|
|
108
110
|
- test/test-hashop.rb
|
109
111
|
- test/test-iterator-method.rb
|
110
112
|
- test/test-apply.rb
|
113
|
+
- test/test-array-minus.rb
|
111
114
|
- test/test-fragile-method-chain.rb
|