@@ -383,7 +383,11 @@ def full; FULL end
383
383
def initialize ( input = nil ) input ? replace ( input ) : clear end
384
384
385
385
# Removes all elements and returns self.
386
- def clear ; @tuples , @string = [ ] , nil ; self end
386
+ def clear
387
+ modifying! # redundant check, to normalize the error message for JRuby
388
+ @tuples , @string = [ ] , nil
389
+ self
390
+ end
387
391
388
392
# Replace the contents of the set with the contents of +other+ and returns
389
393
# +self+.
@@ -439,11 +443,13 @@ def string=(str)
439
443
if str . nil?
440
444
clear
441
445
else
446
+ modifying! # redundant check, to normalize the error message for JRuby
442
447
str = String . try_convert ( str ) or raise ArgumentError , "not a string"
443
448
tuples = str_to_tuples str
444
449
@tuples , @string = [ ] , -str
445
450
tuples_add tuples
446
451
end
452
+ str
447
453
end
448
454
449
455
# Returns the \IMAP +sequence-set+ string representation, or an empty
@@ -780,6 +786,7 @@ def ~; remain_frozen dup.complement! end
780
786
#
781
787
# Related: #add?, #merge, #union, #append
782
788
def add ( element )
789
+ modifying! # short-circuit before input_to_tuple
783
790
tuple_add input_to_tuple element
784
791
normalize!
785
792
end
@@ -794,7 +801,7 @@ def add(element)
794
801
#
795
802
# Related: #add, #merge, #union
796
803
def append ( entry )
797
- modifying!
804
+ modifying! # short-circuit before input_to_tuple
798
805
tuple = input_to_tuple entry
799
806
entry = tuple_to_str tuple
800
807
string unless empty? # write @string before tuple_add
@@ -812,6 +819,7 @@ def append(entry)
812
819
#
813
820
# Related: #add, #merge, #union, #include?
814
821
def add? ( element )
822
+ modifying! # short-circuit before include?
815
823
add element unless include? element
816
824
end
817
825
@@ -824,6 +832,7 @@ def add?(element)
824
832
#
825
833
# Related: #delete?, #delete_at, #subtract, #difference
826
834
def delete ( element )
835
+ modifying! # short-circuit before input_to_tuple
827
836
tuple_subtract input_to_tuple element
828
837
normalize!
829
838
end
@@ -861,6 +870,7 @@ def delete(element)
861
870
#
862
871
# Related: #delete, #delete_at, #subtract, #difference, #disjoint?
863
872
def delete? ( element )
873
+ modifying! # short-circuit before input_to_tuple
864
874
tuple = input_to_tuple element
865
875
if tuple . first == tuple . last
866
876
return unless include_tuple? tuple
@@ -901,6 +911,7 @@ def delete_at(index)
901
911
#
902
912
# Related: #slice, #delete_at, #delete, #delete?, #subtract, #difference
903
913
def slice! ( index , length = nil )
914
+ modifying! # short-circuit before slice
904
915
deleted = slice ( index , length ) and subtract deleted
905
916
deleted
906
917
end
@@ -916,6 +927,7 @@ def slice!(index, length = nil)
916
927
#
917
928
# Related: #add, #add?, #union
918
929
def merge ( *sets )
930
+ modifying! # short-circuit before input_to_tuples
919
931
tuples_add input_to_tuples sets
920
932
normalize!
921
933
end
@@ -1424,6 +1436,7 @@ def limit(max:)
1424
1436
#
1425
1437
# Related: #limit
1426
1438
def limit! ( max :)
1439
+ modifying! # short-circuit, and normalize the error message for JRuby
1427
1440
star = include_star?
1428
1441
max = to_tuple_int ( max )
1429
1442
tuple_subtract [ max + 1 , STAR_INT ]
@@ -1438,6 +1451,7 @@ def limit!(max:)
1438
1451
#
1439
1452
# Related: #complement
1440
1453
def complement!
1454
+ modifying! # short-circuit, and normalize the error message for JRuby
1441
1455
return replace ( self . class . full ) if empty?
1442
1456
return clear if full?
1443
1457
flat = @tuples . flat_map { [ _1 - 1 , _2 + 1 ] }
@@ -1468,6 +1482,7 @@ def normalize
1468
1482
#
1469
1483
# Related: #normalize, #normalized_string
1470
1484
def normalize!
1485
+ modifying! # redundant check, to normalize the error message for JRuby
1471
1486
@string = nil
1472
1487
self
1473
1488
end
@@ -1537,6 +1552,7 @@ def initialize_clone(other)
1537
1552
end
1538
1553
1539
1554
def initialize_dup ( other )
1555
+ modifying! # redundant check, to normalize the error message for JRuby
1540
1556
@tuples = other . tuples . map ( &:dup )
1541
1557
@string = other . string &.-@
1542
1558
super
0 commit comments