سؤال

I found this in Gemspec file of surveyor gem. What does the following line do?

$:.push File.expand_path("../lib", __FILE__)
require "surveyor/version"

Why does the $:.push thing do? To me it looks like its just requires the ../lib/surveyor/version file. if so, can't I just replace that with following one line?

require File.expand_path('../lib/surveyor/version', __FILE__)

Are both these same thing? If not, then what the difference?

هل كانت مفيدة؟

المحلول

$: is Ruby's load path, so it's in fact adding the a subfolder /lib of a folder in which __FILE__ resides to this array, so that other files from this gem can be required.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top