How does the executable in stone refer to the big gem?

Say my gem is VideoPlayer. Folder structure:

VideoPlayer/
    /bin
        vidplay.rb
    /lib
        VideoPlayer.rb
        Subtitler.rb
        Screenshotter.rb

      

I want people to call vidplay

from the command line, and for vidplay

is the link code in the files VideoPlayer

, Subtitler

and Screenshotter

.

If I just write, within vidplay.rb

, require '../lib/VideoPlayer.rb'

it will give an error saying it can not claim such a file. I thought, "Maybe he automatically demands everything in, lib/

" but apparently he doesn't; if I don't require anything, it will say VideoPlayer is an uninitialized constant.

So how does it work?

+3


source to share


1 answer


I usually add the directory lib

to the library load path ( $:

). You can add this to the beginning of the bin file.

lib = File.expand_path('../../lib', __FILE__)
$:.unshift(lib) unless $:.include?(lib)

      

Then you can make a normal request:



require 'videoplayer'

      

Hope it helps.

+1


source







All Articles