哪些ruby模块默认加载?

时间:2014-01-30 22:18:18

标签: ruby

直到最近,我才认为默认情况下不会加载所有标准模块(那些可以在http://ruby-doc.org/stdlib/上看到的模块)。也就是说,您必须要求使用您要使用的每一个。但事实证明,根据$LOADED_FEATURES

的内容判断其中一些确实已加载
$ ruby -rpp -e 'p $LOADED_FEATURES'
["enumerator.so",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/x86_64-linux/enc/encdb.so",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/x86_64-linux/enc/trans/transdb.so",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/x86_64-linux/rbconfig.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/compatibility.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/defaults.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/deprecate.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/errors.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/version.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/requirement.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/platform.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/specification.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/exceptions.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb",                                                                                          
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/prettyprint.rb",
 "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/pp.rb"]

所以我想知道是什么原因,我能以任何方式影响这个吗?

UPD 输出,无需pp

$ ruby -e 'p $LOADED_FEATURES'
["enumerator.so", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/x86_64-linux/enc/encdb.so", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/x86_64-linux/enc/trans/transdb.so", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/x86_64-linux/rbconfig.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/compatibility.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/defaults.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/deprecate.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/errors.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/version.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/requirement.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/platform.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/specification.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/exceptions.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb", "/home/yuri/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems.rb"]

1 个答案:

答案 0 :(得分:2)

我看到加载的唯一库是RubyGems,而且确实在1.9.0中添加了Ruby。

顺便说一句:您没有require module个,require个文件。