> RUBY_VERSION NoMethodError: undefined method `write' for nil-6ren">
gpt4 book ai didi

ruby - irb 中的所有命令都给出 "NoMethodError: undefined method ` write' for nil :NilClass"

转载 作者:数据小太阳 更新时间:2023-10-29 06:55:07 27 4
gpt4 key购买 nike

我正在尝试从 IRB 获取当前的 ruby​​ 版本,但它给我这个错误:

>> RUBY_VERSION
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/ext/multi-irb.rb:166:in `block (2 levels) in irb'
from /usr/local/lib/ruby/1.9.1/irb/ext/multi-irb.rb:165:in `catch'
from /usr/local/lib/ruby/1.9.1/irb/ext/multi-irb.rb:165:in `block in irb'
Maybe IRB bug!

ruby -v显示ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]

我正在使用 Mac OS X Lion

更新:实际上,它根本不运行任何东西。

>> a = 'Hello, World!'
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/ext/multi-irb.rb:166:in `block (2 levels) in irb'
from /usr/local/lib/ruby/1.9.1/irb/ext/multi-irb.rb:165:in `catch'
from /usr/local/lib/ruby/1.9.1/irb/ext/multi-irb.rb:165:in `block in irb'
Maybe IRB bug!

更新 # 2:(针对铁皮人)使用/usr/bin/irb,我得到

>> 5+5
NoMethodError: undefined method `write' for nil:NilClass
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:310:in `printf'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:310:in `output_value'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:159:in `eval_input'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:271:in `signal_status'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:155:in `eval_input'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:244:in `each_top_level_statement'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:230:in `loop'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:230:in `each_top_level_statement'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:229:in `catch'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:229:in `each_top_level_statement'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:154:in `eval_input'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:71:in `start'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:70:in `catch'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:70:in `start'
from /usr/bin/irb:13
Maybe IRB bug!!

最佳答案

尝试 /usr/bin/irb 进入 Apple 的 Ruby 安装。

使用 Leopard 的说明在 Lion 上安装 Ruby 不是一个好主意。您必须记住,语言和操作系统细节会发生变化。

Building Ruby 1.9.3 on Lion with Xcode 4.2 using ./configure --with-gcc=clang”中的信息应该有所帮助。 “Error installing 1.9.3 with RVM on Lion” 也包含有关 XCode 的有用信息。

关于ruby - irb 中的所有命令都给出 "NoMethodError: undefined method ` write' for nil :NilClass",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9166634/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com