# Trouble using Irb as Ruby Console

**URL:** <https://www.ruby-forum.com/t/trouble-using-irb-as-ruby-console/155522>\
**Category:** Ruby\
**Created:** [December 12, 2008, 9:24pm UTC](https://www.ruby-forum.com/t/trouble-using-irb-as-ruby-console/155522 "2008-12-12T21:24:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [December 12, 2008, 9:24pm UTC](https://www.ruby-forum.com/t/trouble-using-irb-as-ruby-console/155522/1 "2008-12-12T21:24:42Z")

</div>

Hello all,

I’m attempting to convert a command-line driven application into a  
console application using Irb. However, I’m having some trouble right  
out of the gate. Here’s what I have so far:

module App  
class Framework  
def use(plugin)  
path = “plugins/#{plugin}”  
tree = plugin.split(’/’)  
tree.collect! { |x| x.capitalize }  
@plugin = Object.const\_get(“App::#{tree.join(’::’)}”).new  
end

```
def show_options
  @plugin.show_options
end

def run
  @plugin.run
end

```

end  
end

binding = App::Framework.new

load ‘irb.rb’  
IRB.setup(nil)  
IRB.conf[:PROMPT][:APP] = IRB.conf[:PROMPT][:SIMPLE]  
IRB.conf[:PROMPT][:APP][:PROMPT\_I] = 'app \> ’  
IRB.conf[:PROMPT\_MODE] = :APP

irb = IRB::Irb.new(IRB::WorkSpace.new(binding))

IRB.conf[:MAIN\_CONTEXT] = irb.context

trap(‘SIGINT’) do  
irb.signal\_handle  
end

catch(:IRB\_EXIT) do  
irb.eval\_input  
end

Essentially, I’m setting the App::Framework class to be my Irb context.  
When I run this program and try to load a plugin named ‘test’ using the  
‘use’ method, I get the following:

antfarm \> use test  
ArgumentError: wrong number of arguments  
from (irb):1:in `test’  
from (irb):1  
from :0  
antfarm \>

From this, it looks like ‘test’ might be a keyword in Irb, because when  
I use a different plugin name I get the following:

antfarm \> use hello  
NameError: undefined local variable or method `hello’ for  
#Antfarm::Framework:0xb7c4c16c  
from (irb):1  
from :0  
antfarm \>

From this, it looks like ‘use’ might be a keyword as well. I’m having  
trouble finding good documentation on Irb Contexts, so if there are any  
Irb experts out there please help!!!

–  
Thanks!  
Bryan

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [December 12, 2008, 9:29pm UTC](https://www.ruby-forum.com/t/trouble-using-irb-as-ruby-console/155522/2 "2008-12-12T21:29:45Z")

</div>

Oops… the console results should say ‘App’ instead of ‘Antfarm’. This  
discrepancy has nothing to do with my problem… 🙂

–  
Thanks!  
Bryan

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [December 12, 2008, 10:59pm UTC](https://www.ruby-forum.com/t/trouble-using-irb-as-ruby-console/155522/3 "2008-12-12T22:59:45Z")

</div>

Bryan R. wrote:

> ```
> tree = plugin.split('/')
> end
> 
> ```
> 
> end  
> antfarm \>
> 
> > From this, it looks like ‘use’ might be a keyword as well. I’m having  
> > trouble finding good documentation on Irb Contexts, so if there are any  
> > Irb experts out there please help!!!

The string “test” (and also “hello”) is getting evaluated. Try putting  
it in quotes, so that it evals to a string and the #use method is passed  
the string.
