Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Easier Path Construction Using Overloaded /

DZone's Guide to

Easier Path Construction Using Overloaded /

· ·
Free Resource
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}"


Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}