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?
push() is a Ruby array method that is used to add elements at the end of an array. This method returns the array itself. One important aspect of this is that this method can be chained.
The push() method adds new items to the end of an array. The push() method changes the length of the array. The push() method returns the new length.
pop() in Ruby? pop() is a Ruby array method that pops or removes the last element of a given array. It permanently removes the last element of an array.
$:
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 require
d.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With