With IRB Link to heading
- Add
irb
to yourGemfile
(yes you need to do this)!
# frozen_string_literal: true
gem 'irb'
-
Run
bundle install
of course! -
Create a
./bin/console
file containing:
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'rubygems'
require 'bundler/setup'
require 'irb'
require_relative '../config/environment.rb'
IRB.start
-
Be sure you require all your project files in
config/environment.rb
. -
Make your file executable:
chmod +x ./bin/console
- Now you can run it like any other program:
./bin/console
# irb(main):001:0>
- Optional but fancy: create a
Makefile
with this content so you can executemake console
instead.
.PHONY: console
console:
@./bin/console
- Pro Tip: use
load 'path/to/file.rb'
to reload file instead of restarting the shell on every edit.
With Pry Link to heading
Step 1. becomes:
# frozen_string_literal: true
gem 'irb'
gem 'pry-byebug'
Yes, you always need irb
in your Gemfile
!
Step 3. becomes:
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'rubygems'
require 'bundler/setup'
require 'pry'
require_relative '../config/environment.rb'
Pry.start
See also: How to Use: pry-byebug