wood burning stoves*
The moose likes Other Languages and the fly likes Ruby Question: Problems with IRB & simple Draw app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "Ruby Question: Problems with IRB & simple Draw app" Watch "Ruby Question: Problems with IRB & simple Draw app" New topic
Author

Ruby Question: Problems with IRB & simple Draw app

Unnsse Khan
Ranch Hand

Joined: Nov 12, 2001
Posts: 511
:-) Hello again,

I am a Ruby newbie... I am using the following version on Mac OS X Tiger:

Raven:/Developer/DevResources/Ruby/Draw untz$ ruby --version
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
Raven:/Developer/DevResources/Ruby/Draw untz$ which ruby
/usr/bin/ruby

I am experiencing several problems....

1. My irb doesn't support tab completion (the same version of Ruby
on WinXP does support tab completion)...

For example:

Raven:/Developer/DevResources/Ruby/Draw untz$ irb
irb(main):001:0> a = "Hello Ruby Group"
=> "Hello Ruby Group"
irb(main):002:0> a.rev

When I click on the tab key right after rev, it doesn't complete it by
printing out the remaining characters belonging to the word 'reverse'.

Is there a way to check and see if this functionality is turned on for irb?

2. How do I use similar functionality in irb to clear the buffer, as one would
do in Unix using "clear" and WinXP, using "cls"?

3. I copied a simple Draw coding sample and when I tried to run it,
I got an error...

The code for Draw.rb:

Raven:/Developer/DevResources/Ruby/Draw untz$ cat Draw.rb
#!/usr/bin/ruby -w

require 'tk'

class Draw

def initialize(parent)
@canvas = TkCanvas.new(parent)
@canvas.pack
@start_x = @start_y = 0
@canvas.bind("1", lambda {|e| do_press(e.x, e.y)})
@canvas.bind("B1-Motion", lambda {|x, y| do_motion(x,y)}, "%x %y")
@canvas.bind("Button-Release-1", lambda {|x, y| do_release(x,y)}, "%x %y")
end

def do_press(x,y)
@start_x = x
@start_y = y
@current_line = TkcLine.new(@canvas, x, y, x,y)
end

def do_motion(x,y)
if @current_line
@current_line.coords @start_x, @start_y, x, y
end
end

def do_release(x,y)
if @current_line
@current_line.coords @start_x, @start_y, x, y
@current_line.fill 'black'
@current_line = nil
end
end

end

root = TkRoot.new { title 'Canvas' }
Draw.new(root)
Tk.mainloop

The error message:

Raven:/Developer/DevResources/Ruby/Draw untz$ ./Draw.rb
/usr/lib/ruby/1.8/tk.rb:1496:in `_invoke_without_enc': bad event type or keysym "Release" (RuntimeError)
from /usr/lib/ruby/1.8/tk.rb:1496:in `_ip_invoke_core'
from /usr/lib/ruby/1.8/tk.rb:1532:in `_tk_call_core'
from /usr/lib/ruby/1.8/tk.rb:1560:in `tk_call_without_enc'
from /usr/lib/ruby/1.8/tk.rb:831:in `_bind_core'
from /usr/lib/ruby/1.8/tk.rb:839:in `_bind'
from /usr/lib/ruby/1.8/tk.rb:921:in `bind'
from /usr/lib/ruby/1.8/tk.rb:2139:in `bind'
from ./Draw.rb:13:in `initialize'
from ./Draw.rb:39:in `new'
from ./Draw.rb:39

Many, many thanks!

-Unnsse
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Ruby Question: Problems with IRB & simple Draw app
 
Similar Threads
ruby script/server is not working
JDK 1.4 Updates broke something on OS X Tiger
Ruby on Rails question: yaml problem with scaffold generation
Problem running Tomcat 5.5.9 on OS X Tiger
Getting Error When uploading Via SOAP API in Ruby