What alternatives to IRB are there?
Asked Answered
D

9

33

In the python world, there are a number of alternative python interpreters that add cool additional features. One particularly useful example is bpython, which adds dynamic syntax highlighting, automatically pulls documentation, and displays live autocomplete information. In the Ruby world, I have yet to uncover any projects which add to the basic IRB interpreter even a subset of these features. Am I just not looking hard enough, or is this just something the Ruby community is lacking?

Dastard answered 7/10, 2010 at 18:33 Comment(0)
A
29

What a coincidence. Rubyflow just yesterday announced the irbtools gem, which is a meta-gem containing lots of cool irb enhancement gems. It contains:

  • Colorized and output as comment by wirb and fancy_irb
  • Nice IRB prompt and IRB’s auto indention
  • Includes stdlib’s FileUtils: ls, cd, pwd, ln_s, rm, mkdir, touch, cat
  • Many debugging helpers: ap, q, o, c, y, Object#m, Object#d
    • ap – awesome_print
    • q – like p, but on one line
    • Object#m – ordered method list (takes integer parameter: level of nesting)
    • Object#d – puts the object, returns self (using tap)
  • “Magical” information constants: Info, OS, RubyVersion, RubyEngine
    • OS.windows?
    • RubyEngine.jruby?
    • RubyVersion.is.at_least? 1.9
  • Clipboard features: copy and paste
    • also available: copy_input and copy_output for session history
  • Call vim (or another supported editor) to edit a file, close it and it gets loaded into your current irb session, powered by interactive_editor
  • Another way of live loading into irb: sketches
  • Highlight a string with olorize('string') or a file with ray('path'), powered by coderay
  • Displays ActiveRecord database entries as tables with hirb
  • Restart irb with reset! or change the Ruby version with the use method and rvm!
  • Includes the current directory in the load path (was removed in 1.9.2 for security reasons, but is pretty annoying in IRB)
  • Shorter requiring like this: rq:mathn
  • And rerquiring with rrq
  • Try the included Object#ri helper, powered by ori!
  • Access to a lot of more commands with boson – call commands to get started

There are nice screenshots on the irbtools page. One nice thing about it is that each of the utilities can stand on its own, in case you just want to cherry-pick one or two features.

2013 Update

Since I wrote this, Pry has become a popular IRB replacement. It doesn't do as much as irbtools out of the box, but it extensible with plugin gems that add cool features. You can browse source code like it was a unix directory:

pry(main)> cd FileUtils
pry(FileUtils):1> show-method rm

From: /opt/ruby/lib/ruby/1.9.1/fileutils.rb @ line 556:
Number of lines: 10
Owner: FileUtils

def rm(list, options = {})
  fu_check_options options, OPT_TABLE['rm']
  list = fu_list(list)
  fu_output_message "rm#{options[:force] ? ' -f' : ''} #{list.join ' '}" if options[:verbose]
  return if options[:noop]

  list.each do |path|
    remove_file path, options[:force]
  end
end
pry(FileUtils):2>

You can also browse Ruby documentation, issue shell commands, and if you're a Rails user, you can use the pry-rails gem to get pry in your Rails console. There's also a way to hook it into Sinatra and use it with Heroku.

There's ample documentation--there are a bunch of screencasts including a Railscast. It's definitely worth looking into.

Archaean answered 7/10, 2010 at 20:10 Comment(2)
This seems out of date now. Pry, mentioned below, has gained enough momentum that it seems to be the preferred alternative to irb.Fifteen
Thanks for the pointer to Pry. It looks great! It has a different focus than irbtools--it does more code introspection. No longer will I be envious of Python's REPL. :) However, I don't think irbtools is out of date, because it has been updated for Rails 3 and still works for me.Archaean
B
35

Use Pry: https://github.com/pry/pry

Let's you:

  • start sessions at runtime
  • view method source code
  • view method documentation (not using RI so you dont have to pre-generate it)
  • pop in and out of different contexts
  • syntax highlighting
  • gist integration
  • view and replay history
  • open editors to edit method using edit-method obj.my_method syntax

A tonne more great and original features

Barbecue answered 28/4, 2011 at 1:50 Comment(0)
A
29

What a coincidence. Rubyflow just yesterday announced the irbtools gem, which is a meta-gem containing lots of cool irb enhancement gems. It contains:

  • Colorized and output as comment by wirb and fancy_irb
  • Nice IRB prompt and IRB’s auto indention
  • Includes stdlib’s FileUtils: ls, cd, pwd, ln_s, rm, mkdir, touch, cat
  • Many debugging helpers: ap, q, o, c, y, Object#m, Object#d
    • ap – awesome_print
    • q – like p, but on one line
    • Object#m – ordered method list (takes integer parameter: level of nesting)
    • Object#d – puts the object, returns self (using tap)
  • “Magical” information constants: Info, OS, RubyVersion, RubyEngine
    • OS.windows?
    • RubyEngine.jruby?
    • RubyVersion.is.at_least? 1.9
  • Clipboard features: copy and paste
    • also available: copy_input and copy_output for session history
  • Call vim (or another supported editor) to edit a file, close it and it gets loaded into your current irb session, powered by interactive_editor
  • Another way of live loading into irb: sketches
  • Highlight a string with olorize('string') or a file with ray('path'), powered by coderay
  • Displays ActiveRecord database entries as tables with hirb
  • Restart irb with reset! or change the Ruby version with the use method and rvm!
  • Includes the current directory in the load path (was removed in 1.9.2 for security reasons, but is pretty annoying in IRB)
  • Shorter requiring like this: rq:mathn
  • And rerquiring with rrq
  • Try the included Object#ri helper, powered by ori!
  • Access to a lot of more commands with boson – call commands to get started

There are nice screenshots on the irbtools page. One nice thing about it is that each of the utilities can stand on its own, in case you just want to cherry-pick one or two features.

2013 Update

Since I wrote this, Pry has become a popular IRB replacement. It doesn't do as much as irbtools out of the box, but it extensible with plugin gems that add cool features. You can browse source code like it was a unix directory:

pry(main)> cd FileUtils
pry(FileUtils):1> show-method rm

From: /opt/ruby/lib/ruby/1.9.1/fileutils.rb @ line 556:
Number of lines: 10
Owner: FileUtils

def rm(list, options = {})
  fu_check_options options, OPT_TABLE['rm']
  list = fu_list(list)
  fu_output_message "rm#{options[:force] ? ' -f' : ''} #{list.join ' '}" if options[:verbose]
  return if options[:noop]

  list.each do |path|
    remove_file path, options[:force]
  end
end
pry(FileUtils):2>

You can also browse Ruby documentation, issue shell commands, and if you're a Rails user, you can use the pry-rails gem to get pry in your Rails console. There's also a way to hook it into Sinatra and use it with Heroku.

There's ample documentation--there are a bunch of screencasts including a Railscast. It's definitely worth looking into.

Archaean answered 7/10, 2010 at 20:10 Comment(2)
This seems out of date now. Pry, mentioned below, has gained enough momentum that it seems to be the preferred alternative to irb.Fifteen
Thanks for the pointer to Pry. It looks great! It has a different focus than irbtools--it does more code introspection. No longer will I be envious of Python's REPL. :) However, I don't think irbtools is out of date, because it has been updated for Rails 3 and still works for me.Archaean
A
3

I've never heard of a (popular) alternative to IRB, but there certainly are several useful gems that make the IRB experience a lot nicer:

  • awesome_print pretty prints Ruby objects with indentation and coloring, very useful when trying to look at nested hashes or other complicated data structures.
  • looksee is pretty awesome too, it provides a method lp (lookup path) that shows you where a Ruby object gets its methods from (class, superclass etc).
  • Sketches connects your editor and IRB, so it's especially useful if you are the type who likes interactive development. Emacs with inf-ruby is also good for this.
  • Wirble is a whole set of IRB enhancements, like tab completion and syntax highlighting. There's also Utility Belt, but I don't personally use that, so can't comment on its features.

Edit

I forgot Hirb, which is very useful for e.g. showing the results of an ActiveRecord query in a Rails console.

Antisepticize answered 7/10, 2010 at 19:11 Comment(0)
L
2

There's http://github.com/alloy/dietrb.

Langmuir answered 7/10, 2010 at 18:59 Comment(2)
There’s still much work to be done. That said, including version 0.6 which I’ve just pushed, DietRB comes with the following features: cleaner implementation, code and file path completion, colorization with Wirble template support, and auto-indentation. rubygems.org/gems/dietrbFuturistic
Oh, and note that it’s only targeted at MRI 1.9, and MacRuby, because it uses Ripper.Futuristic
S
2

JRuby ships with jirb_swing, which provides code completion.

Spectrograph answered 7/10, 2010 at 19:41 Comment(0)
A
1

There's not much in the area of alternatives to irb, but there are a couple of gems that add useful features to irb.

Most notably wirble, which, among other things, gives you colored output (not input though) and a history that goes beyond the current session.

Aleksandr answered 7/10, 2010 at 18:40 Comment(1)
wirble giving you irb autocompletion is incorrect. Irb ships with it. wirble just requires it: require 'irb/completion'Sawdust
S
1

Check out ripl, a modular irb alternative which is designed to be extendable. You may also get some answers from Is there something like bpython for Ruby?.

Sawdust answered 7/10, 2010 at 19:39 Comment(0)
R
0

rib is a modular and light Ruby interactive shell.

It, like Pry, uses Ruby's parser so has consistent behavior with Ruby thus less bugs (e.g. https://mcmap.net/q/452715/-why-rails-can-use-if-as-hash-key-but-not-in-ruby)

It is modular so one can easily extend it with more functionalities.

It is also still actively maintained as of 2016.

Renin answered 29/12, 2016 at 6:19 Comment(0)
S
0

I made a pure Ruby console, inspired off Google Chrome's JavaScript console.

https://github.com/sancarn/RubyConsole

It's still mostly a WIP project as I keep finding bugs with the current algorithm, however I'm building it to be 1.9.3+ compatible.

Slily answered 22/6, 2018 at 8:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.