Rib and .irbrc files

Hi,

Up till now I’ve just had a single .irbrc file in one directory
(gemplay) which does a require_relative to the individual files in my
gem so that when working on the gem I don’t have to uninstall and
reinstall the gem again with small changes and I’ve just been running
irb from that one directory.

I’ve recently wanted to be in a position where if I’m in any other
directory and start irb I want it to load the gem using require
‘gem_name’. I thought I’d be able to achieve that by adding a .irbrc
file to my home directory while keeping the old behaviour when starting
.irbrc from the (gemplay) directory. I get the opposite behaviour to
what I was expecting, and the documentation confirms that my
expectations were wrong:

http://ruby-doc.com/docs/ProgrammingRuby/html/irb.html

that the home directory .irbrc file has highest priority and it can’t be
overridden by the .irbrc file in the working directory.

Is there a clean workaround?, or do I need to do a check in the home
directory .irbrc file to see if there is a .irbrc file in the working
directory and load that (if that is even possible) and also to check
that the working directory is not the home directory.

Thanks
Kevin

On Fri, Aug 1, 2014 at 1:32 PM, Kevin M. [email protected] wrote:

Is there a clean workaround?, or do I need to do a check in the home directory
.irbrc file to see if there is a .irbrc file in the working directory and load
that (if that is even possible) and also to check that the working directory is
not the home directory.

Yes, that would be the proper solution IMHO. I checked a shell
function as alternative but could not find a good way to make irb load
a specific file. You may be pull off something by using ruby -r irb
-e ‘IRB.start’ but that seems overly complicated to me.

Kind regards

robert

There are also another issues like ruby’s -r switch expects file with
.rb extension and need to be placed in a known load path or explicitly
specified by -I.
At the start irb would load $HOME/.irbrc which may be also undesirable.
If passed -f switch it not only suppress reading of ~/.irbrc, but .irbrc
from current directory also.

Just place something like that at the top of your ~/.irbrc and you are
done:

begin
load ‘.irbrc’ # or construct an absolute path
puts ‘Warning: using .irbrc from current directory !’
rescue LoadError => ex

rest of your main .irbrc goes here


end