解决方案根据Mark Setchell和Jared Beck的评论,/etc/irbrc随当前(10.13)OS X一起安装,并且至少已经发布了几个主要版本./p>我将/etc/irbrc复制到〜/.irbrc,运行irb,退出并出现错误:undefined method 'nitems' for ["exit"]:Array (NoMethodError).该方法存在于Ruby 1.8中,但已从Ruby 1.9中删除.我通常不会看到此错误,所以我得出结论说/etc/irbrc根本没有执行.总的来说,我的结论是,在调试〜/.irbrc问题时,可以忽略/etc/irbrc,这是我的问题所在.While investigating an issue with irb on my Mac (OS X 10.11.5) I noticed /etc/irbrc. The first few lines follow:# Some default enhancements/settings for IRB, based on# http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricksunless defined? ETC_IRBRC_LOADED # Require RubyGems by default. require 'rubygems' # Activate auto-completion. require 'irb/completion'# continued ...It seems to be out of date (rubygarden.org is gone, rubygems is in the standard library these days) and does things that I always thought I had to do in my own ~/.irbrc (set up completion, history, etc.).It is dated 31 Jan 2016. I might or might not have run an Apple system update or upgraded something else on that date; I don't recall. I've definitely upgraded OS X by a major version or two since then.I don't think I have any Rubies installed on this computer other than that from OS X and a Ruby 2.3.1 installed with rbenv (in my own account, not as root). That is, I don't think this file could have come from anything other than OS X.Unix shell convention would lead me to expect that a file named /etc/irbrc would be executed when any user ran irb, before their ~/.irbrc if they had one. However, the irb installed by OS X doesn't appear to read this file: I put puts 1 at the top and don't see the result when I run irb. (I normally use rbenv, but disabled it while investigating this file.) /etc/irbrc doesn't appear to run whether or not I have an ~/.irbrc. Also, I see no mentions of this file in /usr/bin/irb or /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb.My guess is that this fileis installed by OS Xis not read by irb as is (despite its misleading name and location), but is intended to be copied to ~/.irbrc.Does anyone know for sure, or know any different?I don't need or want it; I'm happy to maintain my own ~/.irbrc. I just want to be sure that it isn't affecting irb when I run it (in particular, the irb in the rbenv-installed Ruby that I normally use), and that future OS X upgrades won't change irb behavior. 解决方案 Per Mark Setchell's and Jared Beck's comments, /etc/irbrc is installed with current (10.13) OS X and has been for at least a few major releases.I copied /etc/irbrc to ~/.irbrc, ran irb, exited and got an error: undefined method 'nitems' for ["exit"]:Array (NoMethodError). This method existed in Ruby 1.8 but was removed from Ruby 1.9. I don't normally see this error, so I conclude that /etc/irbrc isn't executed at all.Overall, I conclude that I can ignore /etc/irbrc when debugging issues with my ~/.irbrc, which was the origin of my question. 这篇关于OS X是否安装了/etc/irbrc? irb会读吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-25 02:02