@@ -174,7 +174,7 @@ class IMAP
174
174
#
175
175
# <i>Set membership:</i>
176
176
# - #include? (aliased as #member?):
177
- # Returns whether a given object (nz-number, range, or <tt>*</tt>) is
177
+ # Returns whether a given element (nz-number, range, or <tt>*</tt>) is
178
178
# contained by the set.
179
179
# - #include_star?: Returns whether the set contains <tt>*</tt>.
180
180
#
@@ -239,13 +239,13 @@ class IMAP
239
239
# These methods do not modify +self+.
240
240
#
241
241
# - #| (aliased as #union and #+): Returns a new set combining all members
242
- # from +self+ with all members from the other object .
242
+ # from +self+ with all members from the other set .
243
243
# - #& (aliased as #intersection): Returns a new set containing all members
244
- # common to +self+ and the other object .
244
+ # common to +self+ and the other set .
245
245
# - #- (aliased as #difference): Returns a copy of +self+ with all members
246
- # in the other object removed.
246
+ # in the other set removed.
247
247
# - #^ (aliased as #xor): Returns a new set containing all members from
248
- # +self+ and the other object except those common to both.
248
+ # +self+ and the other set except those common to both.
249
249
# - #~ (aliased as #complement): Returns a new set containing all members
250
250
# that are not in +self+
251
251
# - #limit: Returns a copy of +self+ which has replaced <tt>*</tt> with a
@@ -258,17 +258,17 @@ class IMAP
258
258
#
259
259
# These methods always update #string to be fully sorted and coalesced.
260
260
#
261
- # - #add (aliased as #<<): Adds a given object to the set; returns +self+.
262
- # - #add?: If the given object is not an element in the set, adds it and
261
+ # - #add (aliased as #<<): Adds a given element to the set; returns +self+.
262
+ # - #add?: If the given element is not fully included the set, adds it and
263
263
# returns +self+; otherwise, returns +nil+.
264
- # - #merge: Merges multiple elements into the set; returns +self+.
264
+ # - #merge: Adds all members of the given sets into this set; returns +self+.
265
265
# - #complement!: Replaces the contents of the set with its own #complement.
266
266
#
267
267
# <i>Order preserving:</i>
268
268
#
269
269
# These methods _may_ cause #string to not be sorted or coalesced.
270
270
#
271
- # - #append: Adds a given object to the set, appending it to the existing
271
+ # - #append: Adds the given entry to the set, appending it to the existing
272
272
# string, and returns +self+.
273
273
# - #string=: Assigns a new #string value and replaces #elements to match.
274
274
# - #replace: Replaces the contents of the set with the contents
@@ -279,13 +279,14 @@ class IMAP
279
279
# sorted and coalesced.
280
280
#
281
281
# - #clear: Removes all elements in the set; returns +self+.
282
- # - #delete: Removes a given object from the set; returns +self+.
283
- # - #delete?: If the given object is an element in the set, removes it and
282
+ # - #delete: Removes a given element from the set; returns +self+.
283
+ # - #delete?: If the given element is included in the set, removes it and
284
284
# returns it; otherwise, returns +nil+.
285
285
# - #delete_at: Removes the number at a given offset.
286
286
# - #slice!: Removes the number or consecutive numbers at a given offset or
287
287
# range of offsets.
288
- # - #subtract: Removes each given object from the set; returns +self+.
288
+ # - #subtract: Removes all members of the given sets from this set; returns
289
+ # +self+.
289
290
# - #limit!: Replaces <tt>*</tt> with a given maximum value and removes all
290
291
# members over that maximum; returns +self+.
291
292
#
@@ -318,9 +319,12 @@ class SequenceSet
318
319
class << self
319
320
320
321
# :call-seq:
321
- # SequenceSet[*values ] -> valid frozen sequence set
322
+ # SequenceSet[*inputs ] -> valid frozen sequence set
322
323
#
323
- # Returns a frozen SequenceSet, constructed from +values+.
324
+ # Returns a frozen SequenceSet, constructed from +inputs+.
325
+ #
326
+ # When only a single valid frozen SequenceSet is given, that same set is
327
+ # returned.
324
328
#
325
329
# An empty SequenceSet is invalid and will raise a DataFormatError.
326
330
#
@@ -690,16 +694,16 @@ def ~; remain_frozen dup.complement! end
690
694
alias complement :~
691
695
692
696
# :call-seq:
693
- # add(object ) -> self
697
+ # add(element ) -> self
694
698
# self << other -> self
695
699
#
696
700
# Adds a range or number to the set and returns +self+.
697
701
#
698
702
# #string will be regenerated. Use #merge to add many elements at once.
699
703
#
700
704
# Related: #add?, #merge, #union
701
- def add ( object )
702
- tuple_add input_to_tuple object
705
+ def add ( element )
706
+ tuple_add input_to_tuple element
703
707
normalize!
704
708
end
705
709
alias << add
@@ -708,38 +712,38 @@ def add(object)
708
712
#
709
713
# Unlike #add, #merge, or #union, the new value is appended to #string.
710
714
# This may result in a #string which has duplicates or is out-of-order.
711
- def append ( object )
715
+ def append ( entry )
712
716
modifying!
713
- tuple = input_to_tuple object
717
+ tuple = input_to_tuple entry
714
718
entry = tuple_to_str tuple
715
719
string unless empty? # write @string before tuple_add
716
720
tuple_add tuple
717
721
@string = -( @string ? "#{ @string } ,#{ entry } " : entry )
718
722
self
719
723
end
720
724
721
- # :call-seq: add?(object ) -> self or nil
725
+ # :call-seq: add?(element ) -> self or nil
722
726
#
723
727
# Adds a range or number to the set and returns +self+. Returns +nil+
724
- # when the object is already included in the set.
728
+ # when the element is already included in the set.
725
729
#
726
730
# #string will be regenerated. Use #merge to add many elements at once.
727
731
#
728
732
# Related: #add, #merge, #union, #include?
729
- def add? ( object )
730
- add object unless include? object
733
+ def add? ( element )
734
+ add element unless include? element
731
735
end
732
736
733
- # :call-seq: delete(object ) -> self
737
+ # :call-seq: delete(element ) -> self
734
738
#
735
739
# Deletes the given range or number from the set and returns +self+.
736
740
#
737
741
# #string will be regenerated after deletion. Use #subtract to remove
738
742
# many elements at once.
739
743
#
740
744
# Related: #delete?, #delete_at, #subtract, #difference
741
- def delete ( object )
742
- tuple_subtract input_to_tuple object
745
+ def delete ( element )
746
+ tuple_subtract input_to_tuple element
743
747
normalize!
744
748
end
745
749
@@ -775,8 +779,8 @@ def delete(object)
775
779
# #string will be regenerated after deletion.
776
780
#
777
781
# Related: #delete, #delete_at, #subtract, #difference, #disjoint?
778
- def delete? ( object )
779
- tuple = input_to_tuple object
782
+ def delete? ( element )
783
+ tuple = input_to_tuple element
780
784
if tuple . first == tuple . last
781
785
return unless include_tuple? tuple
782
786
tuple_subtract tuple
@@ -820,33 +824,31 @@ def slice!(index, length = nil)
820
824
deleted
821
825
end
822
826
823
- # Merges all of the elements that appear in any of the +inputs + into the
827
+ # Merges all of the elements that appear in any of the +sets + into the
824
828
# set, and returns +self+.
825
829
#
826
- # The +inputs+ may be any objects that would be accepted by ::new:
827
- # non-zero 32 bit unsigned integers, ranges, <tt>sequence-set</tt>
828
- # formatted strings, other sequence sets, or enumerables containing any of
829
- # these.
830
+ # The +sets+ may be any objects that would be accepted by ::new: non-zero
831
+ # 32 bit unsigned integers, ranges, <tt>sequence-set</tt> formatted
832
+ # strings, other sequence sets, or enumerables containing any of these.
830
833
#
831
- # #string will be regenerated after all inputs have been merged.
834
+ # #string will be regenerated after all sets have been merged.
832
835
#
833
836
# Related: #add, #add?, #union
834
- def merge ( *inputs )
835
- tuples_add input_to_tuples inputs
837
+ def merge ( *sets )
838
+ tuples_add input_to_tuples sets
836
839
normalize!
837
840
end
838
841
839
- # Removes all of the elements that appear in any of the given +objects+
840
- # from the set, and returns +self+.
842
+ # Removes all of the elements that appear in any of the given +sets+ from
843
+ # the set, and returns +self+.
841
844
#
842
- # The +objects+ may be any objects that would be accepted by ::new:
843
- # non-zero 32 bit unsigned integers, ranges, <tt>sequence-set</tt>
844
- # formatted strings, other sequence sets, or enumerables containing any of
845
- # these.
845
+ # The +sets+ may be any objects that would be accepted by ::new: non-zero
846
+ # 32 bit unsigned integers, ranges, <tt>sequence-set</tt> formatted
847
+ # strings, other sequence sets, or enumerables containing any of these.
846
848
#
847
849
# Related: #difference
848
- def subtract ( *objects )
849
- tuples_subtract input_to_tuples objects
850
+ def subtract ( *sets )
851
+ tuples_subtract input_to_tuples sets
850
852
normalize!
851
853
end
852
854
@@ -1386,30 +1388,30 @@ def initialize_dup(other)
1386
1388
super
1387
1389
end
1388
1390
1389
- def input_to_tuple ( obj )
1390
- obj = input_try_convert obj
1391
- case obj
1392
- when *STARS , Integer then [ int = to_tuple_int ( obj ) , int ]
1393
- when Range then range_to_tuple ( obj )
1394
- when String then str_to_tuple ( obj )
1391
+ def input_to_tuple ( entry )
1392
+ entry = input_try_convert entry
1393
+ case entry
1394
+ when *STARS , Integer then [ int = to_tuple_int ( entry ) , int ]
1395
+ when Range then range_to_tuple ( entry )
1396
+ when String then str_to_tuple ( entry )
1395
1397
else
1396
- raise DataFormatError , "expected number or range, got %p" % [ obj ]
1398
+ raise DataFormatError , "expected number or range, got %p" % [ entry ]
1397
1399
end
1398
1400
end
1399
1401
1400
- def input_to_tuples ( obj )
1401
- obj = input_try_convert obj
1402
- case obj
1403
- when *STARS , Integer , Range then [ input_to_tuple ( obj ) ]
1404
- when String then str_to_tuples obj
1405
- when SequenceSet then obj . tuples
1406
- when Set then obj . map { [ to_tuple_int ( _1 ) ] * 2 }
1407
- when Array then obj . flat_map { input_to_tuples _1 }
1402
+ def input_to_tuples ( set )
1403
+ set = input_try_convert set
1404
+ case set
1405
+ when *STARS , Integer , Range then [ input_to_tuple ( set ) ]
1406
+ when String then str_to_tuples set
1407
+ when SequenceSet then set . tuples
1408
+ when Set then set . map { [ to_tuple_int ( _1 ) ] * 2 }
1409
+ when Array then set . flat_map { input_to_tuples _1 }
1408
1410
when nil then [ ]
1409
1411
else
1410
1412
raise DataFormatError ,
1411
1413
"expected nz-number, range, string, or enumerable; " \
1412
- "got %p" % [ obj ]
1414
+ "got %p" % [ set ]
1413
1415
end
1414
1416
end
1415
1417
0 commit comments