Skip to content

Default @return on explicit writer method #1567

Answered by lsegal
svoop asked this question in Q&A
Discussion options

You must be logged in to vote

It's of course possible to add an explicit @return to the writer docstring.

Typically you would document @return [void] for an explicit setter. If you couple this with --hide-void-return, you get a realistic representation of your typical attr_* contract.

Even though Ruby's implementation of attr_writer will return the value outright, the actual contract should not be to use attribute setters as return values, i.e., value = obj.center_xy = 1 is a notable code smell that most modern linters will warn you about pretty quickly. This is specifically because your subsequent code that overloads the setter may decide to do fun things after setting the value, and you probably don't want to sign…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by lsegal
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
3 participants
Converted from issue

This discussion was converted from issue #1437 on August 26, 2024 08:48.