當我需要一個文件,例如(稱爲st.rb):紅寶石LoadError:無法加載此類文件
require 'rubygems'
require 'mongrel'
class TestHandler < Mongrel::HttpHandler
def process(request, response)
response.start(200) do |head, out|
head["Content-Type"] = "text/html"
out.write "Hello, World!\n"
end
end
end
在IRB我得到:
>> require 'st.rb'
LoadError: cannot load such file -- st.rb
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):3
from /usr/local/bin/irb:12:in `<main>'
我可能有一個線索,但這只是一個猜測。我的紅寶石版本/安裝位置是:
/usr/local/bin/ruby
和ruby 1.9.3p0
然而,紅寶石的寶石是/usr/local/lib/ruby/1.9.1
,它在談論1.9.1
版本。這可能是原因嗎?
謝謝!
UPDATE 奇怪,當我輸入IRB '使RUBY_VERSION',我得到這個:
puts RUBY_VERSION
1.9.3
NoMethodError: undefined method `write' for nil:NilClass
from /usr/local/lib/ruby/1.9.1/irb.rb:311:in `printf'
from /usr/local/lib/ruby/1.9.1/irb.rb:311:in `output_value'
from /usr/local/lib/ruby/1.9.1/irb.rb:160:in `block (2 levels) in eval_input'
from /usr/local/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
from /usr/local/lib/ruby/1.9.1/irb.rb:156:in `block in eval_input'
from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:243:in `block (2 levels) in each_top_level_statement'
from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
from /usr/local/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
from /usr/local/lib/ruby/1.9.1/irb.rb:70:in `block in start'
from /usr/local/lib/ruby/1.9.1/irb.rb:69:in `catch'
from /usr/local/lib/ruby/1.9.1/irb.rb:69:in `start'
from /usr/local/bin/irb:12:in `<main>'
Maybe IRB bug!
>>
如果你只是'需要'st''怎麼辦? – 2012-02-06 01:00:17
@MatthewLehner同樣的東西 – 0xSina 2012-02-06 01:18:16
[爲什麼不是我的Ruby路徑上的當前目錄?](http://stackoverflow.com/questions/4965556/why-isnt-current-directory-on-my-ruby-path );請參閱我在該問題中的解答以瞭解解決方法。 – Phrogz 2012-02-06 05:17:05