Skip to content

Instantly share code, notes, and snippets.

@rodreegez
Created February 13, 2012 17:36
Show Gist options
  • Save rodreegez/1818506 to your computer and use it in GitHub Desktop.
Save rodreegez/1818506 to your computer and use it in GitHub Desktop.
Ruby 1.9.2 Load paths

via Gregory Brown (@seacreature) on Twitter:

Wrong way to deal with the 1.9.2 removal of . from the loadpath:

  1. require "./foo/bar" forces you to run code from your project root
  2. $LOAD_PATH.unshift(".") recreates security issue, and pollutes

Right way to deal with the 1.9.2 removal of . from the loadpath:

  1. require_relative "foo/bar" if you don't need Ruby 1.8 compatibility
  2. require "#{File.dirname(__FILE__)}/foo/bar" if Ruby 1.8 compatibility needed

Requiring a file somewhere else in the project relative to this file: require File.expand_path('../path/to/file', File.dirname(__FILE__))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment