2014-01-30 51 views
2

直到最近,我還以爲所有的標準模塊(那些可以在http://ruby-doc.org/stdlib/上看到的模塊)在默認情況下都不會被加載。也就是說,你必須要求每一個你將要使用的。但事實證明,他們中的一些確實裝,從$LOADED_FEATURES內容判斷:默認加載哪個ruby模塊?

$ 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"] 
+0

你需要'pp',你可以嘗試打印而不需要'pp' – bjhaid

回答

2

我看到裝載的只有圖書館有RubyGems和確實加入到Ruby 1.9.0中。

順便說一句:你沒有requiremodule s,你require文件。

+0

所以所有這些文件都是加載'rubygems.rb'加載的結果?你知道爲什麼它默認加載嗎? –