Ruby 项目中 "lib" 目录的常规用途是什么?
What is the conventional purpose of the "lib" directory in Ruby projects?
拿这个 ruby gem: https://github.com/ai/autoprefixer-rails
gem的结构包括"lib"、"spec"和"vendor"目录,以及根目录中的一些gem文件。
ruby gem 中名为 "lib" 的目录究竟有何用途?
看起来 "lib" 包含 gem 提供的所有 ruby 代码。 "lib" 也意味着 "the source code files that constitute the library?"(很难说 "lib" 是否意味着 "the library,",因为可以说 gem 文件也是 "part of the library,"。)或者这意味着别的东西? ruby gem 中的目录名称的含义是在任何地方定义的吗?还是目录命名完全随意?
我正在尝试确定名称 "lib" 是否有任何特殊意义,因为我开始编写自己的 gem。我想知道,因为如果没有,我可能想选择一个不同的名字。
默认的 "require path," 即当 gem 激活时默认添加到 $LOAD_PATH 的目录是 "lib"。见 rubygems specification:
REQUIRE_PATHS=(val)
Paths in the gem to add to $LOAD_PATH
when this gem is activated. If
you have an extension you do not need to add "ext"
to the require
path, the extension build process will copy the extension files into
“lib” for you.
The default value is "lib"
Usage:
# If all library files are in the root directory...
spec.require_paths = ['.']
选择名称作为默认名称的事实意味着它也是一个很好的默认命名决定,可以避免额外的配置并帮助新手导航到 gem。
拿这个 ruby gem: https://github.com/ai/autoprefixer-rails
gem的结构包括"lib"、"spec"和"vendor"目录,以及根目录中的一些gem文件。
ruby gem 中名为 "lib" 的目录究竟有何用途?
看起来 "lib" 包含 gem 提供的所有 ruby 代码。 "lib" 也意味着 "the source code files that constitute the library?"(很难说 "lib" 是否意味着 "the library,",因为可以说 gem 文件也是 "part of the library,"。)或者这意味着别的东西? ruby gem 中的目录名称的含义是在任何地方定义的吗?还是目录命名完全随意?
我正在尝试确定名称 "lib" 是否有任何特殊意义,因为我开始编写自己的 gem。我想知道,因为如果没有,我可能想选择一个不同的名字。
默认的 "require path," 即当 gem 激活时默认添加到 $LOAD_PATH 的目录是 "lib"。见 rubygems specification:
REQUIRE_PATHS=(val)
Paths in the gem to add to
$LOAD_PATH
when this gem is activated. If you have an extension you do not need to add"ext"
to the require path, the extension build process will copy the extension files into “lib” for you.The default value is
"lib"
Usage:
# If all library files are in the root directory... spec.require_paths = ['.']
选择名称作为默认名称的事实意味着它也是一个很好的默认命名决定,可以避免额外的配置并帮助新手导航到 gem。