5

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?

3limin4t0r
  • 19,353
  • 2
  • 31
  • 52
Kimmo Lehto
  • 5,910
  • 1
  • 23
  • 32

1 Answers1

3

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.

Sebastián Palma
  • 32,692
  • 6
  • 40
  • 59
ret394
  • 98
  • 6