Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Foundations Testing Test Driven Development

someone explain to me more about $:

Hi I really do not understand what is

$:.unshift File.expand_path(File.dirname(_FILE_) + '/..')

doing, Jason did not say anything useful about it, please can someone explain to me this a little bit?

1 Answer

Milo Winningham
seal-mask
.a{fill-rule:evenodd;}techdegree
Milo Winningham
Web Development Techdegree Student 3,317 Points

$: is shorthand for $LOAD_PATH, a global variable that tells Ruby where to look for files when loading code with require. unshift adds to the beginning of the array, and File.expand_path(File.dirname(_FILE_) + '/..') means the parent directory of the current file. All together, this means that when require 'lib/bank_account' is called, Ruby looks in the directory for this project before anywhere else.

Alternatively, you can use Ruby's require_relative to require a file with a path relative to the current file's directory without modifying the load path. In this case, that would be require_relative '../lib/bank_account'.

Amazing answer! I think is easier use require_relative instead. Regards!