Reputation: 812
I have been renaming some attributes in my Ruby mqtt gem, to match the new MQTT specification. I have been doing this by renaming the attribute and then using alias_method to make sure the old methods still work.
Here is an example of what I have done for renaming the attributes:
# The level number of the protocol
attr_accessor :protocol_level
# @deprecated Please use {#protocol_level} instead
alias_method :protocol_version, :protocol_level
# @deprecated Please use {#protocol_level=} instead
alias_method :protocol_version=, :protocol_level=
However in the generated YARD docs, it doesn't mark it as deprecated and actually makes it look like it is a good alternative name!
- (Object) protocol_level
Also known as: protocol_version
The level number of the protocol
What is the best way to do this? Should I define the old attribute names using a normal method definition instead? I am keen to keep the code concise.
Upvotes: 1
Views: 432
Reputation: 10061
By the looks of the documentation, you are supposed to mark a method as deprecated. Something like
# @deprecated Use {#bar} instead.
def foo
bar
end
def bar
...
end
I realize this is not as succinct as using alias_method
, but I think this is the only way to do it with YARD.
Upvotes: 1