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

Snippets has posted 5883 posts at DZone. View Full User Profile

File.join Shorthand

05.20.2009
| 2533 views |
  • submit to reddit
        A Ruby shorthand for writing foo/bar instead of File.join(foo, bar)

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

Comments

Snippets Manager replied on Mon, 2008/06/23 - 1:39pm

You can also consider applying this to the File and Pathname classes, and calling to_s on other so you can write Pathname.new("/etc") / "foo" / :bar / 1