Last Updated: February 25, 2016
·
583
· tjbladez

Pathname

require 'pathname'
path = Pathname.new('.') # current directory
path += 'lib'          # ./lib
path += 'actors'     # ./lib/actors
path = path.parent       # ./lib
path += 'director.rb'     # ./lib/director.rb
path.read                # contents of ./lib/director.rb
path.open('w'){|io| io << "something"}
path.read                # "something"
path.children{|p| puts p.inspect} # prints all the files/directories in ./lib