Ruby - works with the require command

I am editing a stone in which there are the usual commands requirepointing to the loaded gem (the pearl that I am talking about is called nirvana, but the files in it contain require 'nirvana', require 'nirvana/shell'etc.).

When I use the bin file of the application ( /mypath/nirvana/bin/nirvana), I want the command require 'nirvana'written inside it to point to the files in the local fork of this gem (the ones that I edit), and I want not to load the original nirvana gem, which is installed with the classic gem install.

I do not want to substitute all the commands require 'nirvana'

require File.dirname(File.expand_path(__FILE__)) + '/../lib/nirvana.rb'

... it will solve my problem, but it is ugly! Is there any way not to load the nirvana gem and make require 'nirvana'my libraries load (maybe add them to $ LOAD_PATH ...)?

+3
source share
3 answers

You should only “require” nirvana.rbonce if you do this from the gems binary executable. So this line should appear only once. It is quite common to see how it appears in these files.

Note that your example is better written as

require File.expand_path('../lib/nirvana.rb', __FILE__)

How File :: expand_path takes an optional second argument (String directory).

lib $LOAD_PATH , , .

+2

, require vs. require_relative 1.9+.

require , , .. Ruby.

require_relative , , , , .

`require_relative 'some/sub/dir/to/file'`
+3

rvm, gemsets. gemset, nirvana gem, , require 'nirvana', , .

( , ruby ​​1.9, 1.8, require 'rubygems'.)

+2
source

Source: https://habr.com/ru/post/1793412/


All Articles