Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is /etc/irbrc installed by OS X? Does irb read it?

Tags:

macos

ruby

irb

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/TipsAndTricks

unless 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 file

  • is installed by OS X
  • is 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.

like image 488
Dave Schweisguth Avatar asked Jun 03 '16 14:06

Dave Schweisguth


1 Answers

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.

like image 187
Dave Schweisguth Avatar answered Oct 18 '22 04:10

Dave Schweisguth