Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak docs for Slice#[] methods #7780

Merged
merged 1 commit into from
May 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/slice.cr
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ struct Slice(T)
# slice = Slice.new(5) { |i| i + 10 }
# slice # => Slice[10, 11, 12, 13, 14]
#
# slice2 = slice[1, 3]
# slice2 # => Slice[11, 12, 13]
# slice[1, 3]? # => Slice[11, 12, 13]
# slice[1, 33]? # => nil
# ```
def []?(start : Int, count : Int)
return unless 0 <= start <= @size
Expand All @@ -222,8 +222,8 @@ struct Slice(T)
# slice = Slice.new(5) { |i| i + 10 }
# slice # => Slice[10, 11, 12, 13, 14]
#
# slice2 = slice[1, 3]
# slice2 # => Slice[11, 12, 13]
# slice[1, 3] # => Slice[11, 12, 13]
# slice[1, 33] # raises IndexError
# ```
def [](start : Int, count : Int)
self[start, count]? || raise IndexError.new
Expand All @@ -241,8 +241,8 @@ struct Slice(T)
# slice = Slice.new(5) { |i| i + 10 }
# slice # => Slice[10, 11, 12, 13, 14]
#
# slice2 = slice[1..3]
# slice2 # => Slice[11, 12, 13]
# slice[1..3]? # => Slice[11, 12, 13]
# slice[1..33]? # => nil
# ```
def []?(range : Range)
start, count = Indexable.range_to_index_and_count(range, size)
Expand All @@ -261,8 +261,8 @@ struct Slice(T)
# slice = Slice.new(5) { |i| i + 10 }
# slice # => Slice[10, 11, 12, 13, 14]
#
# slice2 = slice[1..3]
# slice2 # => Slice[11, 12, 13]
# slice[1..3] # => Slice[11, 12, 13]
# slice[1..33] # raises IndexError
# ```
def [](range : Range)
start, count = Indexable.range_to_index_and_count(range, size)
Expand Down