Improvements fro Ruby's IRB console. Everything is colorful and you will get lots of console helpers. Unlike with PRY, you are still in your normal IRB. It is designed to work out-of-the-box so there is no reason to not use it!
$ gem install irbtools
On Linux, you will need xclip or xsel for a functional clipboard: sudo apt-get install xclip
On Windows, you will need ansicon to enable ANSI colors
On Mac OS, you will need growl, to use the g gem
To use irbtools, put the following in your ~/.irbrc file (it is loaded every time you start irb):
If the file does not exist, just create a new one. See further below on how to customize loaded libraries.
To integrate irbtools into a Rails console, you should irbtools to your Gemfile:
gem 'irbtools', require: 'binding.repl'
Thanks to help from the binding.repl gem, you can start IRB (with irbtools) directly from your code:
Another way to activate irbtools in bundler projects is to add a debundle hack at the beginning of your ~/.irbrc file.
When installing irbtools, some gems will not be installed to ensure Windows OS support, e.g. the bond gem for better auto-completion or the looksee gem. These are packaged into the irbtools-more gem. To use irbtools-more, you will need to change your .irbrc to:
Colorizes Ruby objects
Custom views for specific objects, e.g. tables for ActiveRecord
Hash rockets and colorful error messages
Contains helper methods that might be useful in every-day irb usage, see below for details
Easy clipboard access
Lets you open vim (or emacs) from within IRB to hack something that gets loaded into the current session
Print debugging helpers (q, mof, re)
More print debugging (ap)
Colorizes Ruby code (colorize, ray)
malltalk like method finder for Ruby (mf)
Provides Object#mlp (improved version of Module#ancestors) and Object#methods_for(m) (get this method from all ancestors)
Object#src can be shown for Ruby methods
Easily create shortcuts for your favorite methods, even when they are nested, saved in personal yaml file
Command/task framework similar to rake and thor that opens your ruby universe to the commandline and irb
irbtools-more: Better IRB tab-completion
irbtools-more: Great lookup path inspector: Object#l (Extended version of mof), also provides the ability to Object#edit methods.
- fileutils (stdlib)
System utility methods: cd, pwd, ln_s, mv, rm, mkdir, touch
Returns an array with the directory's content
Shortcut for File.read
Shortcut for require library.to_s (allows concise syntax like rq:mathn)
Shortcut for load library.to_s + '.rb'
Little hack for rerequiring a library (it's really hack and not reliable, but works in most cases)
Clears the terminal (system "clear")
Returns all issued commands as a string
irbtools also defines custom helper methods in combination with the loaded gems:
Improves the cd that is already provided by FileUtils (try cd '-')
Aggregates information about your Ruby environment
Syntax highlights a ruby string using CodeRay
Syntax highlights a ruby file using CodeRay
Shortcut for Clipboard.copy
Shortcut for Clipboard.paste
Copies the session_history to the clipboard
Copies this session's results to the clipboard
Shortcut for using the methodfinder
Shortcut for using the pager from hirb
These are the custom public Object methods renamed/patched for some gems
Patching the ri provided by ori to also allow default ri syntax on toplevel
Shortcut for displaying the method source using method_source and coderay
Alternative method name to trigger the looksee gem (irbtools-more)
It is possible to modify, which libraries should get loaded:
# Don't require 'irbtools', but: require 'irbtools/configure' # Here you can modify the libraries using the methods below Irbtools.start
If you do not want to load the default set of irbtools gems, you will have to use require 'irbtools/minimal' instead of configure.
You can use the following methods:
Irbtools.add_library(lib, options_hash, &block)
The options_hash defines the way in which irbtools loads the library. The following options are possible
- (no options)/:start
The library is required on startup before doing anything else (before displaying the prompt)
- :thread => identifier
After loading everything else, the library is required in a thread (while continuing loading). You can choose any identifier, but if you take the same one for multiple libraries, they will be loaded in the same thread (in the order that you define)
- :late => true
The library is required just before showing the prompt (note: loading threads might still be in process)
- :late_thread => identifier
Same as :thread, but after loading late libraries.
- :sub_session => true
The library is loaded every time a sub-session starts (using IRB.conf[:IRB_RC]). In ripl, ripl-after_rc is used.
- :autoload => :Constant
Use Ruby's autoload feature. It loads the library as soon as the constant is encountered.
You can pass a block as third argument, which gets executed after the library has completed loading (except for :autoload, in which case the code will executed directly on startup). You can modify the callbacks by using Irbtools.add_library_callback and Irbtools.replace_library_callback.
When adding a new library, you should firstly consider some way to load it via :autoload. If this is not possible, try loading via :thread. If that is not possible either, you will need to fallback to the default loading mechanism.
If you use double-width unicode characterss, you will need to paste the following snippet to your .irbrc file.
Irbtools.replace_library_callback :fancy_irb do FancyIrb.start east_asian_width: true end
This setting is deactivated by default, because of performance issues.
You can get an about a second faster start-up time by changing the loading methods for wirb and fancy_irb to :thread (drawback: the hash rocket will not be used for the first result):
require 'irbtools/configure' Irbtools.remove_library :paint Irbtools.remove_library :fancy_irb Irbtools.add_library :paint, :late => true do Wirb.load_schema :classic_paint if defined? Wirb end Irbtools.add_library :fancy_irb, :thread => -1 do FancyIrb.start end Irbtools.start
The welcome message can be customized with Irbtools.welcome_message=
Irbtools works well together with the amazing web-console!
Copyright © 2010-2014 Jan Lelis <janlelis.de> released under the MIT license.