Yard, attr_reader and setters


I have a problem with documenting with yard. See this small example:

This is an example class

class MyClass
def initialize
@foo = 0
@bla = 1
attr_reader :foo

# @param [Integer] f sets the value of foo.
def foo=(f)
    @foo = f

# @param [Integer] b sets the value of bla.
def bla=(b)
    @bla = b


When I start yard on this class, the method bla is documented like
expected, but the method foo is left out. If I remove the attr_reader of
@foo the foo method gets also documented. How can I get around this
without to rename my methods to i.e. foo_set or such?

Thanks, detlef

This use case is already described at
https://github.com/lsegal/yard/issues/516 . You’ll find the comment of
the yard maintainer there.

If you are not going to put any code into the manually defined setters
and you can keep them public, then you could write your code like this:

class MyClass
# @return [Integer] Set the foo to a number
attr_accessor :foo

# @return [Integer] Set the bla to a number
attr_accessor :bla

def initialize
    self.foo = 0
    self.bla = 1


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs