-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
improved try documentation #17378
improved try documentation #17378
Conversation
- better `if` example - Added chaining example to the try method description - Documented the `respond_to?` check to the try method description - Clearer wording to explain that argument error is raised on argument mismatch to responding method, rather than to non-responding method (which is handled without exception by `try`) - `.any?` is more precise than `! .blank?` - Don't need to use `try` on `children` as (for regular associations) they will always be a collection or array that responds to `first` - Fix typos/grammar
# | ||
# +try+ will also return +nil+ if the receiver does not respond to the method: | ||
# | ||
# @person.try(:non_existing_method) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please show the return value
Merged manually in df1dda8 |
# | ||
# With +try+ | ||
# @person.try(:children).try(:first).try(:name) | ||
# @person.try(:children).first.try(:name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@egilburg why was this changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad I misread the code :-( I'll make a fix pr soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops nvm I see you already reverted it, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chancancode @egilburg I missed this sorry, thanks for fixing it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, thanks all! 😄
if
examplerespond_to?
check to the try method descriptiontry
).any?
is more precise than! .blank?
try
onchildren
as (for regular associations) they will always be a collection or array that responds tofirst