How to Add a Console to Sinatra Applications

Tagged sinatra, pry, console  Languages ruby

In your application directory, create .pryrc:

Pry.config.editor = "gvim --nofork"

# Print Ruby version at startup
Pry.config.hooks.add_hook(:when_started, :say_hi) do
  puts "Using Ruby version #{RUBY_VERSION}"
end

# Require Sinatra application
require 'config/environment'

Now you can start the console by typing:

$ pry
# or with bundler :(
$ bundle exec pry