Created
September 20, 2010 07:23
-
-
Save koraktor/587533 to your computer and use it in GitHub Desktop.
YARD question: Documenting multiple attr_reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
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.