新手问题 求教 ruby -Ilib 这里的-Ilib 是什么意思

shiren1118 · 2013年01月07日 · 最后由 shiren1118 回复于 2013年01月08日 · 3677 次阅读

看别人测试 gem 下的 bin 下的可执行文件

比如,.是自己建的 gem 目录

|-- Gemfile
|-- LICENSE.txt
|-- README.md
|-- Rakefile
|-- bin
|   `-- truee
|-- lib
|   |-- truee
|   |   |-- translator.rb
|   |   `-- version.rb
|   `-- truee.rb
`-- truee.gemspec

测试方法

% ruby -Ilib ./bin/truee  

求教 ruby -Ilib 这里的-Ilib 是什么意思

《The Ruby Programming Language》P391:

-Ipath: This option adds the directories in path to the beginning of the global $LOAD_PATH array.

所以,执行这个命令后,会把 lib 文件夹加到 load path 的最前面,执行 ./bin/truee 这个可执行文件,如果其中加载了 truee(一般都会加载),那么就直接在 lib 文件夹中寻找 truee.rb

这么做是为了便于开发时测试,因为不用安装这个在开发的 gem。

$ ruby -h
Usage: ruby [switches] [--] [programfile] [arguments]
  -0[octal]       specify record separator (\0, if no argument)
  -a              autosplit mode with -n or -p (splits $_ into $F)
  -c              check syntax only
  -Cdirectory     cd to directory, before executing your script
  -d              set debugging flags (set $DEBUG to true)
  -e 'command'    one line of script. Several -e's allowed. Omit [programfile]
  -Eex[:in]       specify the default external and internal character encodings
  -Fpattern       split() pattern for autosplit (-a)
  -i[extension]   edit ARGV files in place (make backup if extension supplied)
  -Idirectory     specify $LOAD_PATH directory (may be used more than once) 
  -l              enable line ending processing
  -n              assume 'while gets(); ... end' loop around your script
  -p              assume loop like -n but print line also like sed
  -rlibrary       require the library, before executing your script
  -s              enable some switch parsing for switches after script name
  -S              look for the script using PATH environment variable
  -T[level=1]     turn on tainting checks
  -v              print version number, then turn on verbose mode
  -w              turn warnings on for your script
  -W[level=2]     set warning level; 0=silence, 1=medium, 2=verbose
  -x[directory]   strip off text before #!ruby line and perhaps cd to directory
  --copyright     print the copyright
  --version       print the version

#1 楼 非常感谢@andor_chen ,豁然开朗啊

#2 楼 @hooopo 你是说-Idirectory?

#5 楼 @hooopo 实话说,第一次真的没想到-Idirectory 和 -Ilib 是一样的,哈哈

需要 登录 后方可回复, 如果你还没有账号请 注册新账号