Sometimes when you try to run your file, you may get an error because the file is not in your Ruby path. You can:
Run irb -I.
to fix this but this is a pain. You could alias irb
to irb -I.
...
You could also use bundle console
to open irb with your gem code loaded (assuming that you _are_using bundler).
You could also...
task :console do
require 'irb'
require 'mah_lib'
ARGV.clear
IRB.start
end
But that is essentially what bundle console
does. An alternate approach is to:
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'bundler/setup'
require 'your-gem-name'
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start
require 'irb'
IRB.start
Set that as bin/console
and it will run the right thing. This is what bundle generates when you bundle gem your-gem
.
But probably you just want to bundle console
. :)