Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snazzy url fixer using Ruby's super method (See related posts)

Within the body of a method, a call to super acts just like a call to that original method, except that the search for a method body starts in the superclass of the object that was found to contain the original method.

  def url=(addr)
    super (addr.blank? || addr.starts_with?('http')) ? addr : "http://#{addr}"
  end



You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts