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

Fix: documentation of #step in Number and Char #10966

Merged
merged 1 commit into from
Jul 24, 2021
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/char.cr
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ struct Char
self - other
end

# Performs a `#step` in the direction of the _limit_. For instance:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The external name of the parameter is to. Should we use that or the internal one? 🤔

Suggested change
# Performs a `#step` in the direction of the _limit_. For instance:
# Performs a `#step` in the direction of _to_. For instance:

"limit" sounds better, and I suppose that's the entire reason for using an internal name. So it's probably fine as it is, just want to double check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also wonder about this and decided for limit but without being entirely convinced

#
# ```
# 'd'.step(to: 'a').to_a # => ['d', 'c', 'b', 'a']
# 'a'.step(to: 'd').to_a # => ['a', 'b', 'c', 'd']
# ```
def step(*, to limit = nil, exclusive : Bool = false, &)
if limit
direction = limit <=> self
Expand All @@ -133,6 +139,7 @@ struct Char
end
end

# :ditto:
def step(*, to limit = nil, exclusive : Bool = false)
if limit
direction = limit <=> self
Expand Down
7 changes: 6 additions & 1 deletion src/number.cr
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ struct Number
%array
end

# :ditto:
# Performs a `#step` in the direction of the _limit_. For instance:
#
# ```
# 10.step(to: 5).to_a # => [10, 9, 8, 7, 6, 5]
# 5.step(to: 10).to_a # => [5, 6, 7, 8, 9, 10]
# ```
def step(*, to limit = nil, exclusive : Bool = false, &) : Nil
if limit
direction = limit <=> self
Expand Down