Andreas Tiefenthaler

Create an interactive console for your library with Pry

When working on a library written in Ruby the interactive part of trying and using it during development is sometimes hard and painful. Tools like irb and Pry can help here a lot. In general every RubyGem should have a console to have your library right at your fingertips. This makes learning the API and becoming a look and feel way easier if someone wants to use your code or contribute to it.

The easiest way to do this with Pry is to push your models into the load path, require them and start a Pry command line.

    ruby ./bin/console.rb
    #!/usr/bin/env ruby
    $LOAD_PATH << 'lib'
    require 'your_models'
    require 'pry'

    Pry::CLI.parse_options

In combination with pry-rescue and pry-debugger or pry-byebug this turns into a very powerful tool to speedup your development process. Within the console predefined structures and objects can be created to DRY up your workflow.