• Stars
    star
    912
  • Rank 48,116 (Top 1.0 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 13 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Improvements for Ruby's IRB console 💎︎

Irbtools [version] [ci]

Irbtools 4 for Current IRB

The current version of Irbtools requires IRB 1.11+ (which Ruby version bundles which IRB?). Please use Irbtools 3 for earlier versions of IRB.

Description

Improves Ruby's IRB with:

  • a default configuration
  • improved syntax highlighting of result objects
  • helpful commands for debugging and introspection

Examples

Show lookup chain and method list grouped by visibility

>> shadow [1,2,3].reverse
=> # ObjectShadow of Object #85280

## Lookup Chain

    [#<Class:#<Array:0x00007fccd9cfac30>>, Array, Enumerable, Object, "…"]

## 141 Public Methods (Non-Class/Object)

    [:&, :*, :+, :-, :<<, :<=>, :==, :[], :[]=, :all?, :any?, :append, :assoc, :at, :bsearch, :bsearch_index, :chain,
    :chunk, :chunk_while, :clear, :collect, :collect!, :collect_concat, :combination, :compact, :compact!, :concat,
    :count, :cycle, :deconstruct, :delete, :delete_at, :delete_if, :detect, :difference, :dig, :drop, :drop_while,
    :each, :each_cons, :each_entry, :each_index, :each_slice, :each_with_index, :each_with_object, :empty?, :entries,
    :eql?, :fetch, :fill, :filter, :filter!, :filter_map, :find, :find_all, :find_index, :first, :flat_map, :flatten,
    :flatten!, :grep, :grep_v, :group_by, :hash, :include?, :index, :inject, :insert, :inspect, :intersect?,
    :intersection, :join, :keep_if, :last, :lazy, :length, :map, :map!, :max, :max_by, :member?, :min, :min_by,
    :minmax, :minmax_by, :none?, :one?, :pack, :partition, :permutation, :pop, :prepend, :product, :push, :rassoc,
    :reduce, :reject, :reject!, :repeated_combination, :repeated_permutation, :replace, :reverse, :reverse!,
    :reverse_each, :rindex, :rotate, :rotate!, :sample, :select, :select!, :shelljoin, :shift, :shuffle, :shuffle!,
    :size, :slice, :slice!, :slice_after, :slice_before, :slice_when, :sort, :sort!, :sort_by, :sort_by!, :sum,
    :take, :take_while, :tally, :to_a, :to_ary, :to_h, :to_s, :to_set, :transpose, :union, :uniq, :uniq!, :unshift,
    :values_at, :zip, :|]

## 2 Private Methods (Non-Class/Object)

    [:initialize, :initialize_copy]

## Object Inspect

    [3, 2, 1]

Show a method list grouped by ancestors

>> look "str"
.
.
.
Comparable
  <  <=  ==  >  >=  between?  clamp
String
  %            crypt                  inspect      squeeze!
  *            dedup                  intern       start_with?
  +            delete                 length       strip
  +@           delete!                lines        strip!
  -@           delete_prefix          ljust        sub
  <<           delete_prefix!         lstrip       sub!
  <=>          delete_suffix          lstrip!      succ
.
.
.

Show source code of a Ruby-based method

>> code SecureRandom.uuid
#
#   /home/dan/.rvm/rubies/ruby-3.2.0/lib/ruby/3.2.0/random/formatter.rb:170
#
# Generate a random v4 UUID (Universally Unique IDentifier).
#
#   require 'random/formatter'
#
#   Random.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
#   Random.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
#   # or
#   prng = Random.new
#   prng.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"
#
# The version 4 UUID is purely random (except the version).
# It doesn't contain meaningful information such as MAC addresses, timestamps, etc.
#
# The result contains 122 random bits (15.25 random bytes).
#
# See RFC4122[https://datatracker.ietf.org/doc/html/rfc4122] for details of UUID.
#
def uuid
  ary = random_bytes(16).unpack("NnnnnN")
  ary[2] = (ary[2] & 0x0fff) | 0x4000
  ary[3] = (ary[3] & 0x3fff) | 0x8000
  "%08x-%04x-%04x-%04x-%04x%08x" % ary
end

Show source code of a natively implemented method

>> code Array#reverse
//
//   https://github.com/ruby/ruby/blob/ruby_3_2/array.c#L3282
//
// Returns a new \Array with the elements of +self+ in reverse order:
//
//   a = ['foo', 'bar', 'two']
//   a1 = a.reverse
//   a1 # => ["two", "bar", "foo"]
static VALUE
rb_ary_reverse_m(VALUE ary)
{
    long len = RARRAY_LEN(ary);
    VALUE dup = rb_ary_new2(len);

    if (len > 0) {
        const VALUE *p1 = RARRAY_CONST_PTR_TRANSIENT(ary);
        VALUE *p2 = (VALUE *)RARRAY_CONST_PTR_TRANSIENT(dup) + len - 1;
        do *p2-- = *p1++; while (--len > 0);
    }
    ARY_SET_LEN(dup, RARRAY_LEN(ary));
    return dup;
}

Find out method signatures (most useful for Ruby-based methods with keyword args)

>> howtocall require
require(path)
>> require "rubygems/user_interaction"
>> ui = Gem::ConsoleUI.new
>> howtocall ui.choose_from_list
choose_from_list(question, list)

Call system commands with $

>> $ git status # displays current git status

Setup

$ gem install irbtools

IRB 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.irb

Optional: 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:

irb

Features

General IRB Improvements

  • Syntax highlighting (wirb / fancy_irb)
  • Loads included libraries efficiently to reduce IRB start-up time
  • Customizable views for specfic options using hirb. By default, ActiveRecord results get displayed as a table.

Included Debugging Methods for IRB

Highlights

  • Lookup and manipulate instance variables / methods with ease using object_shadow
  • Go even further with looksee, the best lookup path inspection tool out there
  • Display a method's source code using code
  • Find methods that turn one value into another value with methodfinder
  • Use VIM from inside IRB

Extra Commands

Commands 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]
IRB's ls?

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 ;)

Ruby Introspection

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

Platform Info

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

General Utils

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

Files and Navigation

Method / Constant Arguments Description Provided By
cat path Read file contents every_day_irb
cd path = nil Change the directory. Can also be used in these forms: ~cd (change to home directory), -cd (change to previous directory) cd
chmod mode, path Set file mode for file fileutils
chmod_R mode, path Set file mode for directory fileutils
chown user, group, path Set file owner for file fileutils
chown_R user, group, path Set file owner for directory fileutils
cp source, destination Copy file fileutils
cp_r source, destination Copy directory fileutils
ls path = "." List directory content cd
ln target, link Create symlink (ln) fileutils
ln_s target, link Create symlink (ln -s) fileutils
ln_sf target, link Create symlink (ln -sf) fileutils
mkdir path Create a new directory fileutils
mkdir_p path Create a new directory (with -p option) fileutils
cp source, destination Move file or directory fileutils
pwd Return current directory fileutils
ray path Syntax highlight a Ruby file coderay, irbtools
rm path Delete a file (rm) fileutils
rm_r path Delete a file or directory (rm -r) fileutils
rm_rf path Delete a file or directory, with force (rm -rf) fileutils
rmdir path Delete an empty directory fileutils

Advanced Tweaking

See CONFIGURE.md.

Troubleshooting: ANSI colors on Windows

Windows: ANSI support can be enabled via ansicon or ConEmu or WSL.

Troubleshooting: Clipboard not working on Linux

Clipboard support requires xsel or xclip. On ubuntu, do:

sudo apt-get install xsel

Hint: Debundle

If you do not want to add Irbtools to your project's Gemfile, you will need a debundle hack. Put it at the beginning of your ~/.irbrc file and you are fine.

Hint: No ANSI / IRB extension

You can use Irbtools without colors/IRB extensions. To do so, put this into ~/.irbrc:

require 'irbtools/non_fancy'
Irbtools.start

J-_-L

Copyright (c) 2010-2023 Jan Lelis https://janlelis.com released under the MIT license.

More Repositories

1

paint

Ruby gem for ANSI terminal colors 🎨︎ VERY FAST
Ruby
364
star
2

clipboard

Ruby access to the clipboard on Windows, Linux, macOS, Java, Cygwin, and WSL 📋︎
Ruby
350
star
3

whirly

Colorful Terminal Spinner for Ruby 😀︎
Ruby
323
star
4

idiosyncratic-ruby.com

Documenting All Ruby Specialities 💎︎
JavaScript
310
star
5

uniscribe

Know your Unicode ✀
Ruby
280
star
6

pws

Command-Line Password Safe 🔐︎
Ruby
210
star
7

unicode-emoji

Up-to-date Emoji Regex in Ruby
Ruby
142
star
8

unibits

Visualize different Unicode encodings in the terminal
Ruby
127
star
9

unicode-display_width

Monospace Unicode character width in Ruby
Ruby
117
star
10

sugar_refinery

Tiny refinements for Ruby
Ruby
110
star
11

productive-sublime-snippets-ruby

Ruby Snippets for Sublime Text
Ruby
107
star
12

stdgems

Ruby's default & bundled gems: The new standard library
Ruby
105
star
13

relaxed.ruby.style

A Relaxed Style Guide for Ruby & Configuration for RuboCop
Ruby
72
star
14

fresh

Fresh Ruby Enhanced SHell
Ruby
71
star
15

wirb

Ruby Object Inspection for IRB
Ruby
70
star
16

unicode-confusable

Unicode::Confusable.confusable? "ℜսᖯʏ", "Ruby"
Ruby
68
star
17

sig

Validate Method Arguments & Results in Ruby
Ruby
58
star
18

fancy_irb

Colors & Hash Rockets in IRB
Ruby
48
star
19

rg

A way to integrate AngularJS into a Rails project using CoffeeScript and Bower.
Ruby
46
star
20

debugging

Improve your Print Debugging
Ruby
42
star
21

unicode-x

Unicode Micro Libraries for Ruby
Ruby
38
star
22

characteristics

Character info under different encodings
Ruby
27
star
23

object_shadow

The Shadow of a Ruby Object lets you See and Manipulate its Instance Variables and Methods
Ruby
27
star
24

value_struct

Read-only structs in Ruby
Ruby
25
star
25

redux.rb

A tiny Ruby redux
Ruby
25
star
26

code

Displays a Ruby method's source code
Ruby
24
star
27

has_many_booleans

This Rails plugin/gem allows you to generate virtual boolean attributes, which get saved in the database as a single bitset integer.
Ruby
23
star
28

microevent.rb

Events for Ruby objects (a.k.a objects with Publish-Subscribe capabilities a.k.a. Observer pattern)
Ruby
23
star
29

ruby.style

Collects Ruby Style Guides
CSS
20
star
30

unicopy

Unicode command-line codepoint dumper
Ruby
20
star
31

unicode-blocks

Unicode Blocks of a Ruby String
Ruby
18
star
32

irbtools-more

irbtools-more adds gems to IRB that may not build out-of-the-box
18
star
33

character.construction

Notable characters, codepoints, and resources
HTML
16
star
34

ruby_version

RubyVersion | Better than RUBY_VERSION
Ruby
15
star
35

better-array

Unobtrusive JavaScript Array Extras
JavaScript
15
star
36

render_react

Pre-render and mount React components from Ruby
Ruby
15
star
37

yyid.ex

Almost a random UUID in Elixir
Elixir
14
star
38

rubybuntu-gedit

Ruby/Rails/Web related gedit language definitions, mime types, styles and snippets.
Ruby
14
star
39

slim_migrations

Let's you write slightly slimmer Rails migrations.
Ruby
14
star
40

unicode-name

Unicode character names in Ruby
Ruby
13
star
41

uke

𝄝 Ukulele CLI Support
Ruby
13
star
42

gedit-external-tools

A repository for useful and handy snippets for gedit's external tools plugin
Shell
13
star
43

derb

Dockerfile.erb
Ruby
11
star
44

unicode-scripts

Unicode Scripts / Script Extensions of a Ruby String
Ruby
11
star
45

boolean2

Boolean2 is a Ruby constant that is an ancestor of true and false.
Ruby
11
star
46

az

From A to Z
Ruby
10
star
47

symbolify

␀ ␁ ␂ ␃ ␄ ␅ ␆ ␇ ␈ ␉ ␊ ␋ ␌ ␍ ␎ ␏ ␐ ␑ ␒ ␓ ␔ ␕ ␖ ␗ ␘ ␙ ␚ ␛ ␜ ␝ ␞ ␟ ␠ ␡
Ruby
9
star
48

micrologger

A minimal logger based on MicroEvent.rb
Ruby
9
star
49

watchbuffy

Which Buffy episode to put on next?
Ruby
8
star
50

ruby_info

RubyInfo | Better than SCRIPT_LINES__
Ruby
8
star
51

productive-sublime-snippets-erb

Productive Sublime Snippets for ERB
Ruby
8
star
52

unicoder

(wip)
Ruby
7
star
53

clipboard_formatter

A clipboard formatter for RSpec
Ruby
7
star
54

unicode-categories

Unicode General Categories of a Ruby String
Ruby
7
star
55

microgem

more gems
Ruby
6
star
56

unicode-types

Basic Unicode Types of a Ruby String
Ruby
6
star
57

rubynetz

Example Usage of Harvester
6
star
58

unicode-sequence_name

Unicode sequence names in Ruby
Ruby
6
star
59

Deutsch.rb

Like English.rb
Ruby
6
star
60

unicode-numeric_value

Convert a Unicode character into its numeric value
Ruby
6
star
61

rubybuntu-language-specs

gtksourceview language specifications for Ruby/Web devoloper's gedit
Ruby
6
star
62

ripl-multi_line

This ripl plugin allows you to evaluate multiple lines of code.
Ruby
6
star
63

ruby_engine

RubyEngine | Better than RUBY_ENGINE
Ruby
6
star
64

rubybuntu-mime

gnome mime types for Ruby/Web developer's gedit
5
star
65

promiseUserMedia.js

Promisified access to getUserMedia & vendor prefixes.
JavaScript
5
star
66

added

Module#added
Ruby
5
star
67

procstar

Provides to_proc implementations for other Ruby classes than just Symbol
Ruby
4
star
68

every_day_irb

Ruby
4
star
69

rusty_clipboard

Ruby 🡪 Rust 🡪 System Clipboard
Ruby
4
star
70

unicode-age

Determine Unicode version required to display a string
Ruby
4
star
71

yyid.rb

Almost a random UUID in Ruby
Ruby
4
star
72

multi_block

Pass multiple blocks to a Ruby method
Ruby
4
star
73

ripl-color_result

This ripl plugin colorizes your results.
Ruby
4
star
74

nem

npm + gem = nem
Ruby
4
star
75

rubybuntu-editor-styles

gtksourceview styles for Ruby/Web devoloper's gedit
4
star
76

ripltools

This meta gem installs a bunch of ripl plugins for a nice-to-use general purpose ripl.
Ruby
4
star
77

named_proc

Named procs and lambdas
Ruby
3
star
78

local_port

Returns the next free local port number to use for your shiny new service
Ruby
3
star
79

nomore

Blocks your computer from accessing domains on the internet
Ruby
3
star
80

cd

Enhanced cd command for the Ruby console.
Ruby
3
star
81

ripl-auto_indent

This ripl plugin indents your multi-line Ruby input.
Ruby
3
star
82

unicode-version

Which level of Unicode and Emoji support is included with Ruby?
Ruby
3
star
83

egonil

Egocentric Nil
Ruby
2
star
84

talk-ruby-unconf-surprises

Ruby is Full of Surprises (Ruby Unconf 2018)
JavaScript
2
star
85

iterate

Kernel#iterate
Ruby
2
star
86

ripl-rocket

Lets you display the ripl result as a comment on the same line.
Ruby
2
star
87

instance_variables_from

Turn bindings, hashes or arrays into instance variables
Ruby
2
star
88

yyid.js

yyid() generates a random uuid* in the browser, uses the crypto api when available
JavaScript
2
star
89

wcswidth-ruby

FFI bindings to libc's wcswidth() to determine the actual display width of strings
Ruby
2
star
90

pws-otp

Experimental OTP support for PWS
Ruby
2
star
91

website

Ruby
2
star
92

null_plus

+nil
Ruby
2
star
93

ripl-color_streams

This ripl plugin colorizes your stdout and stderr streams.
Ruby
2
star
94

yyid-node.js

Almost a random UUID in node.js
JavaScript
1
star
95

yyid.go

Almost a random UUID in Go
Go
1
star
96

communication-map

WebRTC based Location Sharing
CSS
1
star
97

null_question

Adds the null? predicate to Ruby's nil
Ruby
1
star
98

ripl-profiles

This ripl plugin adds a --profile option to ripl that loads profile files in ~/.ripl/profiles before starting ripl
Ruby
1
star
99

exists

Turns null objects into nil
Ruby
1
star