set 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 710e7b1fc1bf38f1d6f54154861953313835891a7b8f30ee52e7663c914f34c7
4
- data.tar.gz: 7f3ecde9cc9456dea795c5977821a8634fcc5e58ddc59ab074675305c8b81abc
3
+ metadata.gz: f64668b1687c9f23c7f608baba3bd5b2455d2d56e435840a547742640f5ced35
4
+ data.tar.gz: 72306f090587dd7a667445e7adaa443c07dae10a067e851d5dcb045d49fa9165
5
5
  SHA512:
6
- metadata.gz: 9ae9bb8e072bd98d7aa2e3fd9baae6f57e49c63e3ccf68705b13a33554c5ac2a5c9544f926f1598c4219f677727b95dd1598f803a4e8f67402c28fa14340cb90
7
- data.tar.gz: 250dafb092c99682f9b5437bbbf2abeeaf6a9e91f3ce6a789f21d92d2f03bd2fa40e47dfe7761ab9dc779cee84b2357c08b8f309ec203e9340c842bee4f9facc
6
+ metadata.gz: 831b03fe1e1ec4c74188fa91f224411d645aab6cd64d99cb499d1e62a4c0f2c3f660bfc6709c4ace1fdec336b5aae3b32691f70262bc9023cbd427a6a1934b8b
7
+ data.tar.gz: 28da11f61439186d2dc7cc091101884fbd1346489720505bcd1dc507c9933893b477696d04c0a832ac26a103cdad9f634b328c3280504fe4ecf7e44e35a75c52
@@ -11,14 +11,12 @@ jobs:
11
11
  os: [ ubuntu-latest, macos-latest ]
12
12
  runs-on: ${{ matrix.os }}
13
13
  steps:
14
- - uses: actions/checkout@master
14
+ - uses: actions/checkout@v2
15
15
  - name: Set up Ruby
16
16
  uses: ruby/setup-ruby@v1
17
17
  with:
18
18
  ruby-version: ${{ matrix.ruby }}
19
19
  - name: Install dependencies
20
- run: |
21
- gem install bundler --no-document
22
- bundle install
20
+ run: bundle install
23
21
  - name: Run test
24
22
  run: rake test
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Set Changelog
2
2
 
3
+ # 1.0.2 (2021-10-25)
4
+
5
+ * Enhancements
6
+ * Allow Set#intersect? and #disjoint? to accept array argument \[[Feature #17838][]] [#18][] ([@jeremyevans][])
7
+ * Make Set#pretty_print IRB::ColorPrinter friendly [#17][] ([@k-tsj][])
8
+ * Improve documentation [#16][], [#20][] ([@BurdetteLamar][])
9
+ * Follow the license change in Ruby and add BSD-2-Clause
10
+
3
11
  # 1.0.1 (2020-12-22)
4
12
 
5
13
  * Enhancements
@@ -19,6 +27,14 @@ This is the first release of set as a gem. Here lists the changes since the ver
19
27
  [#2]: https://github.com/ruby/set/pull/2
20
28
  [#4]: https://github.com/ruby/set/pull/4
21
29
  [#5]: https://github.com/ruby/set/pull/5
22
-
30
+ [#16]: https://github.com/ruby/set/pull/16
31
+ [#17]: https://github.com/ruby/set/pull/17
32
+ [#18]: https://github.com/ruby/set/pull/18
33
+ [#20]: https://github.com/ruby/set/pull/20
34
+ [Feature #17838]: https://bugs.ruby-lang.org/issues/17838
35
+
36
+ [@BurdetteLamar]: https://github.com/BurdetteLamar
37
+ [@jeremyevans]: https://github.com/jeremyevans
38
+ [@k-tsj]: https://github.com/k-tsj
23
39
  [@knu]: https://github.com/knu
24
40
  [@marcandre]: https://github.com/marcandre
@@ -1,6 +1,6 @@
1
1
  begin
2
2
  require 'sorted_set'
3
3
  rescue ::LoadError
4
- raise "The `SortedSet` class has been extracted from the `set` library." \
4
+ raise "The `SortedSet` class has been extracted from the `set` library. " \
5
5
  "You must use the `sorted_set` gem or other alternatives."
6
6
  end
data/lib/set.rb CHANGED
@@ -62,6 +62,163 @@
62
62
  #
63
63
  # - Akinori MUSHA <<knu@iDaemons.org>> (current maintainer)
64
64
  #
65
+ # ## What's Here
66
+ #
67
+ # First, what's elsewhere. \Class \Set:
68
+ #
69
+ # - Inherits from {class Object}[https://docs.ruby-lang.org/en/master/Object.html#class-Object-label-What-27s+Here].
70
+ # - Includes {module Enumerable}[https://docs.ruby-lang.org/en/master/Enumerable.html#module-Enumerable-label-What-27s+Here],
71
+ # which provides dozens of additional methods.
72
+ #
73
+ # In particular, class \Set does not have many methods of its own
74
+ # for fetching or for iterating.
75
+ # Instead, it relies on those in \Enumerable.
76
+ #
77
+ # Here, class \Set provides methods that are useful for:
78
+ #
79
+ # - [Creating a Set](#class-Set-label-Methods+for+Creating+a+Set)
80
+ # - [Set Operations](#class-Set-label-Methods+for+Set+Operations)
81
+ # - [Comparing](#class-Set-label-Methods+for+Comparing)
82
+ # - [Querying](#class-Set-label-Methods+for+Querying)
83
+ # - [Assigning](#class-Set-label-Methods+for+Assigning)
84
+ # - [Deleting](#class-Set-label-Methods+for+Deleting)
85
+ # - [Converting](#class-Set-label-Methods+for+Converting)
86
+ # - [Iterating](#class-Set-label-Methods+for+Iterating)
87
+ # - [And more....](#class-Set-label-Other+Methods)
88
+ #
89
+ # ### Methods for Creating a \Set
90
+ #
91
+ # - ::[] -
92
+ # Returns a new set containing the given objects.
93
+ # - ::new -
94
+ # Returns a new set containing either the given objects
95
+ # (if no block given) or the return values from the called block
96
+ # (if a block given).
97
+ #
98
+ # ### Methods for \Set Operations
99
+ #
100
+ # - [|](#method-i-7C) (aliased as #union and #+) -
101
+ # Returns a new set containing all elements from +self+
102
+ # and all elements from a given enumerable (no duplicates).
103
+ # - [&](#method-i-26) (aliased as #intersection) -
104
+ # Returns a new set containing all elements common to +self+
105
+ # and a given enumerable.
106
+ # - [-](#method-i-2D) (aliased as #difference) -
107
+ # Returns a copy of +self+ with all elements
108
+ # in a given enumerable removed.
109
+ # - [\^](#method-i-5E) -
110
+ # Returns a new set containing all elements from +self+
111
+ # and a given enumerable except those common to both.
112
+ #
113
+ # ### Methods for Comparing
114
+ #
115
+ # - [<=>](#method-i-3C-3D-3E) -
116
+ # Returns -1, 0, or 1 as +self+ is less than, equal to,
117
+ # or greater than a given object.
118
+ # - [==](#method-i-3D-3D) -
119
+ # Returns whether +self+ and a given enumerable are equal,
120
+ # as determined by Object#eql?.
121
+ # - \#compare_by_identity? -
122
+ # Returns whether the set considers only identity
123
+ # when comparing elements.
124
+ #
125
+ # ### Methods for Querying
126
+ #
127
+ # - \#length (aliased as #size) -
128
+ # Returns the count of elements.
129
+ # - \#empty? -
130
+ # Returns whether the set has no elements.
131
+ # - \#include? (aliased as #member? and #===) -
132
+ # Returns whether a given object is an element in the set.
133
+ # - \#subset? (aliased as [<=](#method-i-3C-3D)) -
134
+ # Returns whether a given object is a subset of the set.
135
+ # - \#proper_subset? (aliased as [<](#method-i-3C)) -
136
+ # Returns whether a given enumerable is a proper subset of the set.
137
+ # - \#superset? (aliased as [<=](#method-i-3E-3D])) -
138
+ # Returns whether a given enumerable is a superset of the set.
139
+ # - \#proper_superset? (aliased as [>](#method-i-3E)) -
140
+ # Returns whether a given enumerable is a proper superset of the set.
141
+ # - \#disjoint? -
142
+ # Returns +true+ if the set and a given enumerable
143
+ # have no common elements, +false+ otherwise.
144
+ # - \#intersect? -
145
+ # Returns +true+ if the set and a given enumerable -
146
+ # have any common elements, +false+ otherwise.
147
+ # - \#compare_by_identity? -
148
+ # Returns whether the set considers only identity
149
+ # when comparing elements.
150
+ #
151
+ # ### Methods for Assigning
152
+ #
153
+ # - \#add (aliased as #<<) -
154
+ # Adds a given object to the set; returns +self+.
155
+ # - \#add? -
156
+ # If the given object is not an element in the set,
157
+ # adds it and returns +self+; otherwise, returns +nil+.
158
+ # - \#merge -
159
+ # Adds each given object to the set; returns +self+.
160
+ # - \#replace -
161
+ # Replaces the contents of the set with the contents
162
+ # of a given enumerable.
163
+ #
164
+ # ### Methods for Deleting
165
+ #
166
+ # - \#clear -
167
+ # Removes all elements in the set; returns +self+.
168
+ # - \#delete -
169
+ # Removes a given object from the set; returns +self+.
170
+ # - \#delete? -
171
+ # If the given object is an element in the set,
172
+ # removes it and returns +self+; otherwise, returns +nil+.
173
+ # - \#subtract -
174
+ # Removes each given object from the set; returns +self+.
175
+ # - \#delete_if - Removes elements specified by a given block.
176
+ # - \#select! (aliased as #filter!) -
177
+ # Removes elements not specified by a given block.
178
+ # - \#keep_if -
179
+ # Removes elements not specified by a given block.
180
+ # - \#reject!
181
+ # Removes elements specified by a given block.
182
+ #
183
+ # ### Methods for Converting
184
+ #
185
+ # - \#classify -
186
+ # Returns a hash that classifies the elements,
187
+ # as determined by the given block.
188
+ # - \#collect! (aliased as #map!) -
189
+ # Replaces each element with a block return-value.
190
+ # - \#divide -
191
+ # Returns a hash that classifies the elements,
192
+ # as determined by the given block;
193
+ # differs from #classify in that the block may accept
194
+ # either one or two arguments.
195
+ # - \#flatten -
196
+ # Returns a new set that is a recursive flattening of +self+.
197
+ # \#flatten! -
198
+ # Replaces each nested set in +self+ with the elements from that set.
199
+ # - \#inspect (aliased as #to_s) -
200
+ # Returns a string displaying the elements.
201
+ # - \#join -
202
+ # Returns a string containing all elements, converted to strings
203
+ # as needed, and joined by the given record separator.
204
+ # - \#to_a -
205
+ # Returns an array containing all set elements.
206
+ # - \#to_set -
207
+ # Returns +self+ if given no arguments and no block;
208
+ # with a block given, returns a new set consisting of block
209
+ # return values.
210
+ #
211
+ # ### Methods for Iterating
212
+ #
213
+ # - \#each -
214
+ # Calls the block with each successive element; returns +self+.
215
+ #
216
+ # ### Other Methods
217
+ #
218
+ # - \#reset -
219
+ # Resets the internal state; useful if an object
220
+ # has been modified while an element in the set.
221
+ #
65
222
  class Set
66
223
  include Enumerable
67
224
 
@@ -313,25 +470,35 @@ class Set
313
470
  end
314
471
  end
315
472
 
316
- # Returns true if the set and the given set have at least one
473
+ # Returns true if the set and the given enumerable have at least one
317
474
  # element in common.
318
475
  #
319
476
  # Set[1, 2, 3].intersect? Set[4, 5] #=> false
320
477
  # Set[1, 2, 3].intersect? Set[3, 4] #=> true
478
+ # Set[1, 2, 3].intersect? 4..5 #=> false
479
+ # Set[1, 2, 3].intersect? [3, 4] #=> true
321
480
  def intersect?(set)
322
- set.is_a?(Set) or raise ArgumentError, "value must be a set"
323
- if size < set.size
324
- any? { |o| set.include?(o) }
325
- else
481
+ case set
482
+ when Set
483
+ if size < set.size
484
+ any? { |o| set.include?(o) }
485
+ else
486
+ set.any? { |o| include?(o) }
487
+ end
488
+ when Enumerable
326
489
  set.any? { |o| include?(o) }
490
+ else
491
+ raise ArgumentError, "value must be enumerable"
327
492
  end
328
493
  end
329
494
 
330
- # Returns true if the set and the given set have no element in
331
- # common. This method is the opposite of `intersect?`.
495
+ # Returns true if the set and the given enumerable have
496
+ # no element in common. This method is the opposite of `intersect?`.
332
497
  #
333
498
  # Set[1, 2, 3].disjoint? Set[3, 4] #=> false
334
499
  # Set[1, 2, 3].disjoint? Set[4, 5] #=> true
500
+ # Set[1, 2, 3].disjoint? [3, 4] #=> false
501
+ # Set[1, 2, 3].disjoint? 4..5 #=> true
335
502
  def disjoint?(set)
336
503
  !intersect?(set)
337
504
  end
@@ -667,13 +834,14 @@ class Set
667
834
  alias to_s inspect
668
835
 
669
836
  def pretty_print(pp) # :nodoc:
670
- pp.text sprintf('#<%s: {', self.class.name)
671
- pp.nest(1) {
672
- pp.seplist(self) { |o|
673
- pp.pp o
837
+ pp.group(1, sprintf('#<%s:', self.class.name), '>') {
838
+ pp.breakable
839
+ pp.group(1, '{', '}') {
840
+ pp.seplist(self) { |o|
841
+ pp.pp o
842
+ }
674
843
  }
675
844
  }
676
- pp.text "}>"
677
845
  end
678
846
 
679
847
  def pretty_print_cycle(pp) # :nodoc:
data/set.gemspec CHANGED
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "set"
3
- spec.version = "1.0.1"
3
+ spec.version = "1.0.2"
4
4
  spec.authors = ["Akinori MUSHA"]
5
5
  spec.email = ["knu@idaemons.org"]
6
6
 
7
7
  spec.summary = %q{Provides a class to deal with collections of unordered, unique values}
8
8
  spec.description = %q{Provides a class to deal with collections of unordered, unique values}
9
9
  spec.homepage = "https://github.com/ruby/set"
10
- spec.license = "BSD-2-Clause"
10
+ spec.licenses = ["Ruby", "BSD-2-Clause"]
11
11
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
12
12
 
13
13
  spec.metadata["homepage_uri"] = spec.homepage
@@ -19,7 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
20
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
21
  end
22
- spec.bindir = "exe"
23
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
22
  spec.require_paths = ["lib"]
25
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: set
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinori MUSHA
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-22 00:00:00.000000000 Z
11
+ date: 2021-10-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides a class to deal with collections of unordered, unique values
14
14
  email:
@@ -31,11 +31,12 @@ files:
31
31
  - set.gemspec
32
32
  homepage: https://github.com/ruby/set
33
33
  licenses:
34
+ - Ruby
34
35
  - BSD-2-Clause
35
36
  metadata:
36
37
  homepage_uri: https://github.com/ruby/set
37
38
  source_code_uri: https://github.com/ruby/set
38
- changelog_uri: https://github.com/ruby/set/blob/v1.0.1/CHANGELOG.md
39
+ changelog_uri: https://github.com/ruby/set/blob/v1.0.2/CHANGELOG.md
39
40
  post_install_message:
40
41
  rdoc_options: []
41
42
  require_paths:
@@ -51,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
52
  - !ruby/object:Gem::Version
52
53
  version: '0'
53
54
  requirements: []
54
- rubygems_version: 3.2.1
55
+ rubygems_version: 3.2.22
55
56
  signing_key:
56
57
  specification_version: 4
57
58
  summary: Provides a class to deal with collections of unordered, unique values