Skip to content

Commit 97d3a21

Browse files
committed
📚 Update SequenceSet rdoc for sorted set indexing
1 parent d51d12e commit 97d3a21

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

lib/net/imap/sequence_set.rb

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ class IMAP
183183
# - #max: Returns the maximum number in the set.
184184
# - #minmax: Returns the minimum and maximum numbers in the set.
185185
#
186-
# <i>Accessing value by (normalized) offset:</i>
186+
# <i>Accessing value by offset in sorted set:</i>
187187
# - #[] (aliased as #slice): Returns the number or consecutive subset at a
188-
# given offset or range of offsets.
189-
# - #at: Returns the number at a given offset.
190-
# - #find_index: Returns the given number's offset in the set
188+
# given offset or range of offsets in the sorted set.
189+
# - #at: Returns the number at a given offset in the sorted set.
190+
# - #find_index: Returns the given number's offset in the sorted set.
191191
#
192192
# <i>Set cardinality:</i>
193193
# - #count (aliased as #size): Returns the count of numbers in the set.
@@ -1083,10 +1083,10 @@ def has_duplicates?
10831083
count_with_duplicates != count
10841084
end
10851085

1086-
# Returns the index of +number+ in the set, or +nil+ if +number+ isn't in
1087-
# the set.
1086+
# Returns the (sorted and deduplicated) index of +number+ in the set, or
1087+
# +nil+ if +number+ isn't in the set.
10881088
#
1089-
# Related: #[]
1089+
# Related: #[], #at
10901090
def find_index(number)
10911091
number = to_tuple_int number
10921092
each_tuple_with_index do |min, max, idx_min|
@@ -1120,8 +1120,11 @@ def reverse_each_tuple_with_index
11201120

11211121
# :call-seq: at(index) -> integer or nil
11221122
#
1123-
# Returns a number from +self+, without modifying the set. Behaves the
1124-
# same as #[], except that #at only allows a single integer argument.
1123+
# Returns the number at the given +index+ in the sorted set, without
1124+
# modifying the set.
1125+
#
1126+
# +index+ is interpreted the same as in #[], except that #at only allows a
1127+
# single integer argument.
11251128
#
11261129
# Related: #[], #slice
11271130
def at(index)
@@ -1146,17 +1149,18 @@ def at(index)
11461149
# seqset[range] -> sequence set or nil
11471150
# slice(range) -> sequence set or nil
11481151
#
1149-
# Returns a number or a subset from +self+, without modifying the set.
1152+
# Returns a number or a subset from the _sorted_ set, without modifying
1153+
# the set.
11501154
#
11511155
# When an Integer argument +index+ is given, the number at offset +index+
1152-
# is returned:
1156+
# in the sorted set is returned:
11531157
#
11541158
# set = Net::IMAP::SequenceSet["10:15,20:23,26"]
11551159
# set[0] #=> 10
11561160
# set[5] #=> 15
11571161
# set[10] #=> 26
11581162
#
1159-
# If +index+ is negative, it counts relative to the end of +self+:
1163+
# If +index+ is negative, it counts relative to the end of the sorted set:
11601164
# set = Net::IMAP::SequenceSet["10:15,20:23,26"]
11611165
# set[-1] #=> 26
11621166
# set[-3] #=> 22
@@ -1168,13 +1172,14 @@ def at(index)
11681172
# set[11] #=> nil
11691173
# set[-12] #=> nil
11701174
#
1171-
# The result is based on the normalized set—sorted and de-duplicatednot
1172-
# on the assigned value of #string.
1175+
# The result is based on the sorted and de-duplicated set, not on the
1176+
# ordered #entries in #string.
11731177
#
11741178
# set = Net::IMAP::SequenceSet["12,20:23,11:16,21"]
11751179
# set[0] #=> 11
11761180
# set[-1] #=> 23
11771181
#
1182+
# Related: #at
11781183
def [](index, length = nil)
11791184
if length then slice_length(index, length)
11801185
elsif index.is_a?(Range) then slice_range(index)

0 commit comments

Comments
 (0)