# IRB Module Documentation

**URL:** <https://www.ruby-forum.com/t/irb-module-documentation/112637>\
**Category:** Ruby\
**Created:** [August 21, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/irb-module-documentation/112637 "2007-08-21T17:28:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjml](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sjml](https://www.ruby-forum.com/u/sjml)\
**Post date:** [August 21, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/irb-module-documentation/112637/1 "2007-08-21T17:28:51Z")

</div>

Can anybody point me to some good documentation (either online or  
dead-tree) of the IRB module? The RDoc is pretty bare-bones, and the  
samples I’ve found online aren’t terribly well-commented or  
self-explanatory.

As background: I’m trying to hook up the text-rendering of my OpenGL  
engine to act as a Ruby console. I’ve got it interpreting individual  
lines with eval(), but I’d like to set it up with IRB proper to make use  
of the history, prompting, output, etc.

---

<div class="post-metadata">

**Author:** ![sjml](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sjml](https://www.ruby-forum.com/u/sjml)\
**Post date:** [August 22, 2007, 3:15am UTC](https://www.ruby-forum.com/t/irb-module-documentation/112637/2 "2007-08-22T03:15:16Z")

</div>

Shane Liesegang wrote:

> Can anybody point me to some good documentation (either online or  
> dead-tree) of the IRB module? The RDoc is pretty bare-bones, and the  
> samples I’ve found online aren’t terribly well-commented or  
> self-explanatory.
> 
> As background: I’m trying to hook up the text-rendering of my OpenGL  
> engine to act as a Ruby console. I’ve got it interpreting individual  
> lines with eval(), but I’d like to set it up with IRB proper to make use  
> of the history, prompting, output, etc.

This may not be quite what you’re looking for, but whenever I want to  
add an irb-like shell to a command-line application, I start by mucking  
around with the snippet below (note the difference in the three ways of  
invoking irb). Setting the prompt is easier; look for IRB.conf[:PROMPT]  
in the irb source.

#!/usr/bin/env ruby

require ‘irb’  
require ‘irb/completion’

module IRB  
def IRB.parse\_opts  
# Don’t touch ARGV, which belongs to the app which called this  
module.  
end

def IRB.start\_session(\*args)  
unless $irb  
IRB.setup nil  
## maybe set some opts here, as in parse\_opts in irb/init.rb?  
end

```
 workspace = WorkSpace.new(*args)

 if @CONF[:SCRIPT] ## normally, set by parse_opts
   $irb = Irb.new(workspace, @CONF[:SCRIPT])
 else
   $irb = Irb.new(workspace)
 end

 @CONF[:IRB_RC].call($irb.context) if @CONF[:IRB_RC]
 @CONF[:MAIN_CONTEXT] = $irb.context

 trap 'INT' do
   $irb.signal_handle
 end

 custom_configuration if defined?(IRB.custom_configuration)

 catch :IRB_EXIT do
   $irb.eval_input
 end

 ## might want to reset your app's interrupt handler here

```

end  
end

class Object  
include IRB::ExtendCommandBundle # so that Marshal.dump works  
end

if **FILE** == $0  
x = Object.new  
puts “\nStarted irb shell for x”  
IRB.start\_session(x)  
puts “\nStarted irb shell for x with current binding”  
IRB.start\_session(binding, x)  
puts “\nRestarted irb shell for x with current binding”  
$irb.eval\_input  
puts “\nExited irb shell”  
p x  
end
