Spice up your boring IRB (Irbtools)

irbtools‘, which make using irb easier and more fun. It improves Ruby’s irb console like colored output and lots of helpful methods.

Setup

Install the gem by using:
  gem install irbtools
or Add it to your project’s Gemfile:
gem 'irbtools', require: 'irbtools/binding'

Usage

IRB executes code in ~/.irbrc on start-up.To use irbtools, put the following code in ~/.irbrc file:
require 'irbtools'
We can start IRB directly from the code by calling,
binding.irb
When installing irbtools, some gems will not be installed. For example, the bond gem for better auto-completion. These are packaged as irbtools-more (requires ruby version >= 2.4). To use irbtools-more, change the .irbrc to:
require 'irbtools/more'
and edit Gemfile as
gem 'irbtools-more', require: 'irbtools/binding'
For example, the output looks like: Irbtools

Features

  1. Colorized and output as comment by wirb and fancy_irb
  2. Nice IRB prompt and IRB’s auto indention
  3. Includes stdlib’s FileUtils: ls, cd, pwd, ln_s, rm, mkdir, touch, cat
  4. Many debugging helpers:
    • ap – awesome_print
    • q –like p, but on one line
    • Object#m – ordered method list (takes integer parameter: level of nesting)
    • Objedt#d – puts the object, returns self (using tap)
  5. “Magical” information constants: Info, OS, RubyVersion, RubyEngine
    • OS.windows?
    • RubyEngine.jruby?
    • RubyVersion.is.at_least? 1.9
  6. Clipboard features: copy and paste
  7. Call vim to edit a file, close it and it gets loaded into your current irb session, powered by interactive_editor
  8. Highlight a string with colorize(‘string’) or a file with ray(‘path’), powered by coderay
  9. Displays ActiveRecord database entries as tables with hirb
  10. Restart irb with reset! or change the Ruby version with the use method and rvm!
  11. Includes the current directory in the load path
  12. Shorter requiring like this: rq:mathn
  13. Access to a lot of more commands with boson – call commands to get started

Irbtools Methods

From every_day_irb

ls Returns an array with the directory’s content
cat Shortcut for File.read
rq Shortcut for require library.to_s (allows concise syntax like rq:mathn)
ld Shortcut for load library.to_s + '.rb'
rrq/rerequire Little hack for rerequiring a library
reset! Restarts IRB
clear Clears the terminal (system "clear")
session_history Returns all issued commands as a string

From irbtools in conjunction with the libraries

cd Improves the cd that is already provided by fileutils (try cd ‘-‘)
version Displays RubyVersion
engine Displays RubyEngine
os OS information
info Aggregates information about your Ruby environment
copy Shortcut for Clipboard.copy
paste Shortcut for Clipboard.paste
copy_input Copies the session_history to the clipboard
copy_output Copies this session’s results to the clipboard
mf Shortcut for using the methodfinder
page Shortcut for using the pager from hirb
colorize Syntax highlights a ruby string using coderay
ray Syntax highlights a ruby file using coderay
So next time when you think of improving Ruby’s irb console into a colored, fun and much easier output, don’t forget to remember your friend named irbtools‘.

References

http://irb.tools/ http://tagaholic.me/2009/04/23/how-to-write-a-rubygem-command-plugin.html http://stackoverflow.com/questions/3884715/what-alternatives-to-irb-are-there
]]>