Skip to content

Instantly share code, notes, and snippets.

@koraktor
Created September 20, 2010 07:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koraktor/587533 to your computer and use it in GitHub Desktop.
Save koraktor/587533 to your computer and use it in GitHub Desktop.
YARD question: Documenting multiple attr_reader
# This works:
# @return [String] This is attribute #1
attr_reader :attr1
# @return [Object] This is attribute #2
attr_reader :attr2
# But this won't:
# @attr_reader [String] attr1 This is attribute #1
# @attr_reader [Object] attr2 This is attribute #2
attr_reader :attr1, :attr2
@joshhepworth
Copy link

Did you ever figure out how to get something like this to work?

@koraktor
Copy link
Author

koraktor commented Feb 9, 2012

I think @lsegal told me, that this doesn't (and probably will never). Today, even if it would work I'd also recommend to put each attribute on its own line. This will bloat your code a bit, but it's more readable and provides a place to add notes etc. for each individual attribute.

@leoarnold
Copy link

This can now be done using the @!attribute directive:

# @!attribute [r] name
#   @return [String] The person's full name
#
# @!attribute [r] date_of_birth
#   @return [Date] The person's date of birth
class Person
  attr_reader :name, :date_of_birth

  def initialize(name, date_of_birth)
    @name = name
    @date_of_birth = date_of_birth
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment