YARD: create a custom getter / setter pair, e.g. attr_accessor

I use YARD to document my project. YARD document attributes created using

attr_accessor :some_attribute

in a separate section “Summary of Instance Attributes”. I now have a different attribute, but with a custom installer and getter

def some_other_attribute
  ...
end

def some_other_attribute= value
  ...
end

so basically my question is: how can I get a YARD to document this setter / getter pair, as attr_accessorin the previous case, and list it some_other_attributein the “Instance Attributes Summary”?

+5
source share
2 answers

0,8 ( ) @!attribute , . @attr_* . ( 0.8.0 +):

# @!parse attr_accessor :some_attribute

, Ruby. 0,8 attr_accessor , / :

class MyClass
  attr_accessor :foo
  def foo; something_else end
  def foo=(v) something_else(v) end
end

Ruby , , ruby -w . , undef foo, foo=. ( -w), , @!parse @!attribute.

+5

@attr :

# @attr [String] name The name of this object. 
class MyClass
  def name
  end
  def name=
  end
end

(, @attr_reader @attr_writer), .

+1

All Articles