DZone 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

Shmulik has posted 1 posts at DZone. View Full User Profile

Easier Path Construction Using Overloaded /

03.28.2008
| 3435 views |
  • submit to reddit
        
Especially when writing rake tasks where a lot of path construction code is written the following overloading of the / operator makes the code more readable.


class String
  def /(other)
    File.join(self,other)
  end
end

# and you can write
#   path = all/along/the/watch/tower
# instead of 
#   path = "#{all}/#{along}/#{the}/#{watch}/#{tower}"