1. ripl(1)
  2. Ripl Manual
  3. ripl(1)

NAME

ripl - Ruby Interactive Print Loop - A light, modular alternative to irb

SYNOPSIS

ripl [COMMAND] [-r|--require] [-I] [-f] [-d] [-h|--help] [-v|--version] [ARGS]

DESCRIPTION

ripl is a light, modular alternative to irb. Like irb, it loads ~/.irbrc, has autocompletion and keeps history in ~/.irb_history. Unlike irb, it is highly customizable via plugins and supports commands. This customizability makes it easy to build custom shells (i.e. for a gem or application) and complex shells (i.e. for the web).

COMING FROM IRB

When first trying ripl, you may experience errors in your ~/.irbrc due to an irb-specific configuration. In order to have ripl and irb coexist peacefully, you should silence these errors. To silence them without touching your ~/.irbrc, install the ripl-irb gem. This ripl plugin fakes irb's existence, effectively ignoring irb-specific configuration. Otherwise, if you don't mind modifying ~/.irbrc, wrap your irb-specific configuration in a block as follow:

if defined? IRB
  IRB.conf[:BLAH] = 'blah'
  # ...
end

CONFIGURATION

All ripl shells load the ruby file ~/.riplrc if it exists. In this file, plugins are required and configuration options are set. To configure ripl and its plugins, use Ripl.config. By default, Ripl.config is a hash with the following keys:

:binding

Binding to use for eval(). Default is TOPLEVEL_BINDING.

:completion

A hash that configures completion via Bond.start. See bond for more details.

:history

A file used to store input history. Default is '~/.irb_history'.

:irbrc

A ruby file to load at startup or false to not load anything. Default is '~/.irbrc'.

:name

Name of the shell. Default is 'ripl'.

:prompt

A string or lambda to generate string that prompts user for input. Default is '>> '.

:readline

A boolean to enable Readline. Default is true.

:result_prompt

A string that prefixes the result of an eval. Default is '=> '.

Plugins can optionally provide their own config key(s) for use here. It is strongly recommended that a plugin start with an underscored version of its name i.e. Ripl::ColorError -> Ripl.config[:color_error].

An example ~/.riplrc:

  require 'ripl/multi_line'
  require 'ripl/color_error'
  Ripl.config[:color_error] = :blue

PLUGINS

A ripl plugin is a module that is included into Ripl::Shell or extended into Ripl::Runner. Being simply modules, they can be packaged as gems and reused across shells as needed. ripl highly encourages plugins by loading them as early as possible and allowing them to extend most of ripl's functionality. As mentioned in the CONFIGURATION section, a plugin can be configured via Ripl.config.

To always use a plugin, require it in ~/.riplrc. To sometimes use it, require it from the commandline:

$ ripl -rripl/multi_line

Plugins can also be required in the console but it is not recommended since plugins can depend on initialization that occurs before the console is started. For this same reason, plugins should not be required in ~/.irbrc.

CREATE PLUGINS

For an example shell plugin, let's color error messages red:

require 'ripl'

# To try place in ~/.riplrc
module Ripl
  module RedError
    def format_error(error)
      "\e[31m#{super}\e[m"
    end
  end
end
Ripl::Shell.send :include, Ripl::RedError

Note this plugin extends format_error() by invoking the original format_error() with super. To see what methods are available for extension, see Ripl::Shell::API and Ripl::Runner::API.

Points to consider when creating plugins:

CREATE CUSTOM SHELLS

Creating and starting a custom shell is as simple as:

require 'ripl'
# Define plugins, load files, etc...
Ripl.start

Ripl.start takes the same config keys mentioned in the CONFIGURATION section. For example if you wanted to start on a specific binding:

Ripl.start :binding => MyClass.instance_eval{ binding }

Also, since all shells load ~/.riplrc, Ripl.start can be used to override undesirable global configuration for a custom shell.

COMMANDS

A ripl command is a command passed to ripl that loads a custom shell. It's a convenient way to package and invoke custom shells. A ripl command can take standard ripl options as long as they are before the command:

# Load rails console without ~/.irbrc
$ ripl rails -f

# Load rails console with debugger
$ ripl rails -rrdebug

To create a ripl command, create an executable in the format ripl-command and make sure it's in your shell's $PATH. For example, the file 'ripl-my_gem' would be invoked with 'ripl my_gem'. Any arguments to a ripl command can be parsed as the ripl command pleases i.e. into options and arguments. For an example command, see ripl-rails.

BUGS

Please report bugs at http://github.com/cldwalker/ripl/issues.

ripl is Copyright (C) 2010 Gabriel Horner

SEE ALSO

http://github.com/cldwalker/ripl, http://github.com/cldwalker/bond, http://github.com/cldwalker/nirvana, http://github.com/cldwalker/ripl-irb, http://github.com/cldwalker/ripl-rails, http://github.com/janlelis/multi_line

  1. CLDWALKER
  2. December 2010
  3. ripl(1)