[original text](http://blogger.godfat.org/2011/02/ripl-rc-1-ripl-irb-replacement.html)

# ripl, an irb replacement

<p></p><a href="http://www.urbandictionary.com/define.php?term=TL%3BDR">TL;DR</a>: see the <a href="#comparison">comparison table/list</a> on
the bottom of this post. Still TL;DR?
<pre><code>&gt; gem install ripl
&gt; ripl rc</code></pre>
<img src="https://github.com/godfat/ripl-rc/raw/ripl-rc-0.1.3/screenshot.png"/>

Use it in rails console?
<pre><code>&gt; gem install ripl-rails
&gt; ripl rc rails</code></pre>

# ripl

Days ago when I was using <a href="https://github.com/banister/pry">pry</a> to debug heroku-scaler,
(which is a <a href="https://github.com/Ramaze/ramaze">ramaze</a> and <a href="https://github.com/igrigorik/em-http-request">em-http-request</a> application),
I wanted to make pry use irb history to easy debugging,
and then I found it was talking about something like
pry is not an irb replacement, to find an irb replacement,
see <a href="https://github.com/cldwalker/ripl">ripl</a>. That's where I started playing around with ripl.

At first, I didn't think I need an replacement for irb,
because it worked for me. But as always, we don't know
if we need a better tool until we're really using a better
tool. ripl is this kind of story for me, and so do <a href="https://github.com/lsegal/yard">yard</a> to
<a href="https://github.com/rdoc/rdoc">rdoc</a> and so on so forth. Interestingly, this is not always
true for all tools. For example, I like <a href="https://github.com/jimweirich/rake">rake</a> better than
<a href="https://github.com/wycats/thor">thor</a> (though I didn't really try thor), and didn't really
need the power of <a href="http://www.kuwata-lab.com/erubis/">erubis</a> over erb.

One can think that, using thor/erubis might force others
to do the same (though erubis could be used as a drop-in
replacement for erb), but irb/ripl is just a personal tool
instead of really a library that once you used it in the
application, all developers would be forced to use or test
against it, too. Just like a text editor. Personal taste only..

Back to topic...

So what would we benefit from switching irb to ripl? If
we're only using the core functionality of ripl, then not
even talking about gains, but we'll lose some features
that irb provides but ripl doesn't. What good is, according
to the <a href="https://github.com/cldwalker/ripl/blob/v0.3.2/README.rdoc">README</a> of ripl, the code size was about ~270
lines vs 5,000+ lines, so we can expect that ripl is a lot
easier to extend and customize, and this is also a fact.

ripl is designed to be extended and customized from the
beginning, and since the code is very modular and
lightweight, it's very easy to replicate irb's behavior
and features that are missing in ripl. You can take a look
at ripl-irb. It might grow to be fat after installing many
plugins and extensions, but I guess it will never reach
the size of irb, since irb *has its own ruby parser*...
<a href="https://github.com/janlelis/ripl-multi_line">ripl-multi_line</a> uses a trick that catches syntax error
exception to achieve multiline support. This might be
tricky because it depends on the error message coming
from syntax error; however irb's own ruby parser might
not be accurate as well... as long as it's not using ruby's
own parser.

At first I was trying to add some simple patches with only
a few of lines to the core of ripl to make it better, but the
author only accepted my bug fix patches instead of features
patches, even it's only a few of lines and I don't see why
others won't want that features. Sometimes this make me
feel like vim or bash, you'll definitely want some personal
(might not be so personal though) config files instead of
using the defaults, which is very different than GUI
applications, which always try to provide the best defaults.
I think both have their strength, and I don't mind as long
as it could be customized to suit my flavor, and that's why
I've written <a href="https://github.com/godfat/ripl-rc">ripl-rc</a>.

ripl-rc is a ripl plugins collection, each of its require is a
different plugin. For example:
<pre><code>require 'ripl/rc/color'
require 'ripl/rc/anchor'</code></pre>
The first line would enable colorizing plugin, and the latter
would enable pry session like plugin. The reason I do this
instead of releasing ripl-color, ripl-anchor, etc., is I think
it's a lot easier to maintain and install as a plugin collection,
since each plugin has only a few of codes. We can take
advantage of fixing plugins at the same time, too, since
some plugins would work with other plugins. (e.g.
ripl/rc/anchor and ripl/rc/color) It would be tedious for
users and developers to release or update a bunch of new
releases... I really hate rails doing that, though the code
base is not the same level. It might be a must for rails
somehow...

Enough of rubbish, let's see the comparison.<a id="comparison"></a>

# Comparison

ripl has:

* a lot fewer codes and is a lot easier to customize
* better auto-complete (from <a href="https://github.com/cldwalker/bond">bond</a>)

irb has:

* multiline support (ripl uses ripl-multi_line)
* subsessions and workspaces (actually I don't know
  what are they, never used. ripl uses <a href="https://github.com/cldwalker/ripl-commands">ripl-commands</a>)

ripl-rc has, upon session ends:

* <span style="color:gold">require 'ripl/rc/squeeze_history'</span>

  which squeezes the same input in history, both in memory
  and history file.

* <span style="color:gold">require 'ripl/rc/mkdir_history'</span>

  which calls `mkdir -p` on directory which contains history
  file. For example, I put my irb_history in an directory
  might not exist before use: `~/.config/irb/irb_history`

* <span style="color:gold">require 'ripl/rc/ctrld_newline'</span>

  ruby 1.9.2 has no this problem in irb, but 1.8 and ripl do.
  When hitting ctrl+d to exit ripl, it would print a newline
  instead of messing up with shell prompt.

upon formatting output:

* <span style="color:gold">require 'ripl/rc/strip_backtrace'</span>

  ripl prints the full backtrace upon exceptions, even the
  exceptions come from interactive environment, making it
  very verbose. This ripl plugin strips those backtrace.

* <span style="color:gold">require 'ripl/rc/color'</span>

  There's ripl-color_result that make use of <a href="https://github.com/michaeldv/awesome_print">awesome_print</a>,
  <a href="http://coderay.rubychan.de/">coderay</a>, or <a href="https://github.com/janlelis/wirb">wirb</a>. The problem of awesome_print is it's too
  awesome and too verbose, and the problem of coderay and
  wirb is that they are both parser based. In ripl, this should
  be as simple as just print different colors upon different
  objects, instead of inspecting it and parsing it.

  ripl/rc/color just uses a hash with Class to color mapping
  to pick up which color should be used upon a ruby object.

  To customize the color schema, inspect `Ripl.config[:rc_color]`

upon input:

* <span style="color:gold">require 'ripl/rc/multiline'</span>

  I need some modification on ripl-multi_line to make prompt
  work better, but not sure if I can come up a good fix and
  try to convince the author to accept those patches. So I
  just bundle and maintain it on my own. If you're using
  ripl-rc, you could use this plugin, otherwise, keep using
  ripl-multi_line.

* <span style="color:gold">require 'ripl/rc/eat_whites'</span>

  irb will just give you another prompt upon an empty input,
  while ripl would show you that your input is nil. I don't like
  this, because sometimes I'll keep hitting enter to separate
  between inspects. This plugin would skip inspect if the input
  is empty just like irb.

special tool:

* <span style="color:gold">require 'ripl/rc/anchor'</span>

  So this is my attempt to emulate pry in ripl. Instead
  trying to make pry support irb_history, colorizing, etc.,
  I think implement pry like feature in ripl is a lot easier.
  No need to be fancy, I just need the basic functionality.

  To use it, use:
  <pre><code>Ripl.anchor your_object_want_to_be_viewed_as_self</code></pre>
  or
  <pre><code>Ripl.anchor binding</code></pre>
  in your code. Other than pry ripl support, you might be
  interested in <a href="https://github.com/cldwalker/ripl-rails">ripl-rails</a> and <a href="https://github.com/cldwalker/ripl-hijack">ripl-hijack</a>, too.

about config:

* <span style="color:gold">require 'ripl/rc/noirbrc'</span>

  By default ripl is reading `~/.irbrc`. I don't think this
  is what people still using irb would want, because the
  configuration is totally different. This suppress that,
  make it only read `~/.riplrc`

for lazies:

* <span style="color:gold">require 'ripl/rc'</span>

  This requires anything above for you, and is what `ripl rc`
  and `ripl rc rails` shell commands did.

So that's all at the moment for <a href="https://github.com/godfat/ripl-rc/tree/ripl-rc-0.1.3">ripl-rc 0.1.3</a>. Enjoy,

2010-02-28 (16:36~21:49)