Skip to content
golive edited this page Feb 7, 2012 · 3 revisions

Working with requires and files

Require relative to current file path:

require File.expand_path("../../bin", __FILE__)

Add path to load path ($LOAD_PATH) so we can require files in a folder:

$:.unshift('path/to/files')

Get the filename, extension and dirname:

File.basename("/home/gumby/work/ruby.rb") #=> "ruby.rb"
File.extname("a/b/d/test.rb")             #=> ".rb"
File.dirname("/home/gumby/work/ruby.rb")  #=> "/home/gumby/work"
Clone this wiki locally