• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ruby Question: Problems with IRB & simple Draw app

 
Ranch Hand
Posts: 511
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
:-) 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
 
I've been selected to go to the moon! All thanks to this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic