Skip to content

Default @return on explicit writer method #1437

Description

@svoop

This is best shown with a real life example using a default attribute reader along with an explicit attribute writer which should be documented with overloads as per your comment here:

class Arc
  # Center point
  #
  # @overload center_xy
  #   @return [AIXM::XY]
  # @overload center_xy=(value)
  #   @param value [AIXM::XY]
  attr_reader :center_xy

  def center_xy=(value)
    # do some stuff here
    @center_xy = value
  end
end

However, this documents the writer as follows:

#center_xy=(value) ⇒ Object

While technically correct, it should be:

#center_xy=(value) ⇒ AIXM::XY

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

However, shouldn't the default return of the writer better be the return of the corresponding reader – given how Ruby attribute writer methods work these days?

Update: Actually, that's not true: Ruby these days always returns the parameter of the writer, so a better default for the writer return would be whatever is set for the @param (in this case AIXM::XY from @param value [AIXM::XY]).

Btw: Thanks for YARD, love the generated docs and how well they work with Dash. 🥳

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions