Ruby – Using `Require`

I am editing a gem, which has the usual require command, pointing to the loaded gem (the gem I am talking about is called nirvana, and the file contains require’navana’, require’ navana/shell’ and so on).

When I use the bin file of the application (/mypath/nirvana/bin/nirvana), the require’nirvana’ command that I wish to write in it Point to the files in the local fork of the gem (the files I’m editing), I don’t want to load the original Nirvana gems, it is installed together with the classic gem installation.

I don’t want to use all of them ‘nirvana’ command substitution

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

…This will solve my problem, but it’s ugly! Is there a way to not load the nirvana gem and make require’nirvana’ to load my libraries (maybe add them in $LOAD_PATH …)?

If you use gems binary executable to do this, then you should only need’nirvana. rb’ once. So this line only needs to appear once. It is very common to see it appear in these files.

Please note that your example can be better written as

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

Because File::expand_path takes an optional second parameter (Directory string).

Many authors also transfer the lib directory to $LOAD_PATH before executing the binary, so that local files can be loaded before attempting to load any installed gems.

< /div>

I’m editing a gem, which has the usual require command, pointing to the loaded gem (the gem I’m talking about is called nirvana, and the file contains require’navana’, require’navana /shell’ and so on).

When I use the application’s bin file (/mypath/nirvana/bin/nirvana), the require’nirvana’ command I want to write in it points to The files in the local fork of the gem (the files I’m editing), I don’t want to load the original Nirvana gemstone, it is installed together with the classic gem installation.

I don’t want to use all the’ nirvana’ command substitution

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

… …This will solve my problem, but it’s ugly! Is there a way to not load the nirvana gem and make require’nirvana’ to load my libraries (maybe add them in $LOAD_PATH …)?

If you use gems binary executable to do this, then you should only need’nirvana.rb’ once. So this line only needs to appear once . It is common to see it appear in these files.

Please note that your example can be better written as

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

Because File::expand_path takes an optional second parameter (directory string).

Many authors also transfer the lib directory to $LOAD_PATH before executing the binary, so that local files can be loaded before attempting to load any installed gems.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3283 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.