Skip to content

command line vs. irb vs. rails console

E. Lynette Rayle edited this page May 28, 2022 · 1 revision

Running ruby file on command line

Execute in terminal window.

ruby ruby_file.rb

Starting up an interactive test environment

irb and rails console are both used as an interactive test environment. Each command is executed in the terminal window. exit is used to leave each.

To test ruby basics:

irb

To execute with app's load path:

bundle exec irb

To test in full app context:

bundle exec rails c

loading files

Within irb or rails console:

load ruby_file.rb

Some gems may need a require statement to work:

require 'json'
json_hash = JSON.parse(json_str)