Improvements for Ruby's IRB console ︎
The current version of Irbtools requires IRB 1.13+ (which Ruby version bundles which IRB?). Please use Irbtools 3 for earlier versions of IRB.
Improves Ruby's IRB with:
$>> $ git status # displays current git status…>> look "str"
.
.
.
Comparable
>= between? clamp
String
% crypt inspect squeeze!
* dedup intern start_with?
+ delete length strip
+@ delete! lines strip!
-@ delete_prefix ljust sub
delete_suffix lstrip! succ
.
.
.……>> howtocall require
require(path)>> require "rubygems/user_interaction"
>> ui = Gem::ConsoleUI.new
>> howtocall ui.choose_from_list
choose_from_list(question, list)$ gem install irbtoolsIRB executes code in ~/.irbrc on start-up. If the file does not exist, yet,
just create a new one. Add the following content:
require 'irbtools'You also need to add irbtools to your project's Gemfile:
gem 'irbtools', require: 'irbtools/binding'Then start IRB (with Irbtools loaded) from the terminal or directly from your code with:
binding.irbOptional: If the binding_of_caller gem is available, you can just call the irb
method and it will start a session with the current binding:
irbCommands get treated specially by IRB and do not necessarily follow Ruby syntax.
| Command | Alias | Description | Example |
|---|---|---|---|
code |
- | Shows syntax-highlighted source code of a method | code Array#reverse |
howtocall |
- | Shows the method signature | howtocall String#gsub |
look |
- | Shows looksee method list | look [1,2,3] |
shadow |
+ |
Shows object shadow method list | shadow [1,2,3] |
sys |
$ |
Calls system shell | $ top |
Two default commands have an additional alias:
| Command | Alias | Description | Example |
|---|---|---|---|
show_doc |
ri |
Shows documentation | ri String#gsub |
chws |
co |
"change into an object" | co [1,2,3] |
Please note that IRB's own ls command is aliased to ils, since ls already refers to a method listing all files in the current directory. If you haven't tried looksee (look) or object shadows (shadow) - give it a try ;)
| Method / Constant | Arguments | Description | Provided By |
|---|---|---|---|
Object#lp or Object#look |
Supercharged method introspection in IRB | looksee | |
Object#shadow |
Manipulate instance variables and learn about callable methods | object_shadow | |
code |
object = self, method_name | Display the method source with syntax highlighting. Will also try to look up C methods. | code |
howtocall |
object = self, method_or_proc | Display parameter names and types you will need to call a method | debugging/howtocall |
mf |
object1, object2 | Find methods which turn one value into another value | methodfinder |
| Method / Constant | Arguments | Description | Provided By |
|---|---|---|---|
OS |
Query operating system information | os | |
RubyVersion |
Show the Ruby version | ruby_version | |
RubyEngine |
Show the Ruby engine | ruby_engine |
| Method / Constant | Arguments | Description | Provided By |
|---|---|---|---|
beep |
Ring terminal bell | debugging/beep | |
clear |
Clear the terminal | every_day_irb | |
copy |
string | Copy something to the clipboard | clipboard |
copy_output |
Copy session output history to the clipboard | clipboard, irbtools | |
colorize |
string | Syntax-highlight a string of Ruby code | coderay, irbtools |
ed / emacs / mate / mvim / nano / vi / vim |
filename = nil | Start an editor in the session context | interactive_editor |
ld |
file | Shortcut for load lib.to_s + '.rb' |
every_day_irb |
pa |
string, color | Print a string in the specified color | paint |
page |
what, options = {} | Use pager to improve viewing longer content | hirb, irbtools |
paste |
Paste clipboard content | clipboard | |
q |
*args | Like Kernel#p, but prints results on one line, with different colors |
debugging/q |
re |
string, regexg, groups = nil | Regex debugging helper | debugging/re |
reset! |
Restart the current IRB session | every_day_irb | |
rq |
lib | Shortcut for require lib.to_s. Use it like this: rq:prime |
every_day_irb |
rr |
lib | Shortcut for require_relative lib.to_s |
every_day_irb |
rrq / rerequire |
lib | Hack to remove a library from $LOADED_FEATURES and require it again |
every_day_irb |
wp |
inspect_string | Syntax-highlight a Ruby return value | wirb |
| Method / Constant | Arguments | Description | Provided By | | ----------------- | ------------------- | --------------------------------------------------
No open issues yet, or sync has not completed.