What alternatives to IRB are there?
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
andfancy_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_printq
– likep
, but on one lineObject#m
– ordered method list (takes integer parameter: level of nesting)Object#d
– puts the object, returns self (usingtap
)
- “Magical” information constants:
Info, OS, RubyVersion, RubyEngine
OS.windows?
RubyEngine.jruby?
RubyVersion.is.at_least? 1.9
- Clipboard features:
copy
andpaste
- also available:
copy_input
andcopy_output
for session history
- also available:
- Call
vim
(or another supported editor) to edit a file, close it and it gets loaded into your current irb session, powered byinteractive_editor
- Another way of live loading into irb: sketches
- Highlight a string with
olorize('string')
or a file withray('path')
, powered by coderay - Displays ActiveRecord database entries as tables with
hirb
- Restart
irb
withreset!
or change the Ruby version with theuse
method andrvm!
- 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 byori
! - 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.
Does javascript have something similar to Ruby's `ri`
After some time, I really have to recommend DocHub (https://github.com/rgarcia/dochub)
It's a node app that provides scrapes docs from the web and keeps them locally to make things speedy or let you use them offline.
Equivalent to pry / irb 's _ , but in node?
Node docs:
The special variable
_
(underscore) contains the result of the last expression.
Is there a way to get out of a hung state in IRB?
Press Control + D
once or twice. That should do it.
Is there something like bpython for Ruby?
Use Pry: http://pry.github.com
It is written from scratch and let's you:
- 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
- invoke at runtime, in any context
- 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
Are there any iPython-like shells for Ruby or Rails?
There is an irb tool to help autocomplete
require 'irb/completion'
How can I obtain an interactive shell (like Ruby's irb) for Java?
Would "Use an Eclipse Java Scrapbook page" be better ;-)
I haven't actually used irb, but if you just want to run code snippets inside of eclipse, then this is a simple way of doing it.
Writing a custom IRB
Once you can execute ruby code on the platform you are running on, it's just a matter of gluing up together eval and readline. For something more advanced, I advice you to take a look at the ruby source code, you will find the complete irb sources in bin/irb.rb
, lib/irb.rb
and the lib/irb
direcotry. Have fun!
Related Topics
Ruby Net::Http::Get and JSON Responses
How to Force Activerecord to Reload a Class
Vcrproxy: Record Phantomjs Ajax Calls with Vcr Inside Capybara
Listing the Names of Associated Models
How to Run Ruby Tasks That Use My Rails Models
Ruby Easy Search for Key-Value Pair in an Array of Hashes
Ruby, Check If Date Is a Weekend
Ruby: Cannot Parse Excel File Exported as CSV in Os X
Ruby on Rails, Could Not Find a Valid Gem 'Rails'
Rails - How to Check Developer Mode or Production Mode in Code
Ruby Concatenate Strings and Add Spaces
How to Get Request's Target Controller and Action with Rails 3
How to Use Nokogiri to Parse an Xml File