Kimmo Lehto
Kimmo Lehto

Reputation: 6041

How to document an inherited constructor using Yard

Having classes, such as:

class Foo
  def initialize(data)
  end
end

class Bar < Foo
end

Each subclass that inherits from Foo has its own unique attributes, passed in via the data options hash.

The yard output for Bar states:

Constructor Details
This class inherits a constructor from Foo

I haven't been able to figure out how to document the options for Bar#initialize.

Attempts include:

class Bar < Foo
  # @overload initialize(data)
  #   @param data [Hash]
  #   @option data [String] :baz Value for baz attribute
end

(does nothing)

class Bar < Foo
  # @param data [Hash]
  # @option data [String] :baz Value for baz attribute
  # @!parse def initialize(data); end
end

(creates an undocumented constructor with "view source" showing the fake method)

class Bar < Foo
  # @!parse
  #   @param data [Hash]
  #   @option data [String] :baz Baz attr
  #   def initialize(data); end
end

(does nothing, result is the same as with @overload above)

How can I document the options for the subclasses using YARD?

Upvotes: 5

Views: 728

Answers (1)

ret394
ret394

Reputation: 98

Try using this with yard. And ruby version 2.6

class Foo
  def initialize(data)
  end
end

class Bar < Foo
  # @overload initialize(data)
  # @param [String] data list
  # def initialize()
  # end
end

And check the generated class_list.html file.

Tested it on a Linux distro.


If there's any other technical issue, or you need a customized Ruby documentation solution as a temporary measure.

Upvotes: 3

Related Questions