0

While building a Project in Ruby I am required to document every important piece of code with RDoc, using YARD, the bulk of the work is done via Command Patterns Classes (from GOF).

The main structure of a Command Pattern is similar to this one:

class Command
  def initialize(specific, params, for, command); end
  def execute
    # The specific code goes here
  end
end

So the definition of the Command is basically the Class name, and instead of calling their execute methods with the specific parameters, you prepare them beforehand and then you just call execute.

So, does it make sense to document the initialize method or should the Class should be documented, here are my alternatives:

The "classic" YARD way (I'm in no way an expert in documentation)

# Generates a reservation for a user in an hotel room in certain date
class ReserveHotelRoom < Command
  # Initializes the Use Case
  # @param user [User] user which is making the reservation
  # @param hotel [Hotel] hotel which is being booked
  # @param room [String] room number/name
  # @param date [Datetime] date for the reservation
  def initialize(user:, hotel:, room:, date:); end
end

I think that a most "proper" way should be something like this, but kind of breaks YARD because I don't get the full support from its labels.

# Generates a Reservation for a user in an hotel room in a certain date
# @!attribute user [User]
# @!attribute hotel [Hotel] hotel which is being booked
# @!attribute room [String] room number/name
# @!attribute date [Datetime] date for the reservation
class ReserveHotelRoom < Command
  # No documentation should be necessary inside because everything is 'standard'
end
Lomefin
  • 1,173
  • 12
  • 43
  • RDoc is for documentation, meant to be consumed by humans. If you have two different ways of documenting it, and both ways conform to the RDoc standard, then there is no "proper" way of doing it; you pick the way that makes most sense to you and to the people you expect to consume the documentation in the future. This isn't a question with a solidly correct answer. It's a meatspace problem. – anothermh Jul 09 '20 at 21:28
  • Yes, my bad, I was trying to find a way to make YARD with its labels as much as possible and I had it confused with RDoc. – Lomefin Jul 11 '20 at 18:47

0 Answers0