Ruby Quicktips Logo

Ruby Quicktips

Random Ruby and Rails tips.
This blog is dedicated to deliver short, interesting and practical tidbits of the Ruby language and Ruby on Rails framework. Read more...

Your submissions are more than welcome!
Mar 27 ’12

Mark Deprecated Code in Ruby

To mark deprecated code in Ruby simply add a comment to the rdoc and call the Kernel#warn method. For example:

class Foo
  # DEPRECATED: Please use useful instead.
  def useless
    warn "[DEPRECATION] `useless` is deprecated.  Please use `useful` instead."
    useful
  end

  def useful
    # ...
  end
end

If you’re using Yard instead of rdoc, your doc comment should look like this:

# @deprecated Please use {#useful} instead

Also, don’t forget to remove the deprecated method in some future release.

Source: Ryan McGeary’s answer on stackoverflow.

11 notes 0 comments

  1. tetsuo692 reblogged this from rubyquicktips
  2. toronya reblogged this from rubyquicktips
  3. rmdhn-blog submitted this to rubyquicktips

Comments

You can use HTML tags for formatting. Wrap code in <code> tags and multiple lines of code in <pre><code> tags.

blog comments powered by Disqus