Hi,

In message "Problem with Ruby Tk"
    on 02/01/28, Peter Hickman <peter / semantico.com> writes:
|
|I'm having some problems with the following code. When I click on either 
|of the buttons on the scrollbar or move the thumb within the scrollbar 
|the program crashes out on me. The error message that follows is from 
|Windows 1.6.5-2 but the same error turns up on two seperate Linux 
|installs. As the code is mostly cut and paste from the Pickaxe book I am 
|somewhat baffled. BTW the Pickaxe code works fine but then it is not in 
|a class.
|
|Any pointers?

Since Ruby/Tk's "self swap" hack, you can't access instance variables
from the block to the "new" method.

|                scroll = TkScrollbar.new(root) {
|                        command proc { |*args| @text.yview *args}
|                        pack('side' => 'right', 'fill' => 'y')
|                }

"@text" in the block is referring the instance variable of the new
TkScrollbar.  You can avoid this by

!                text = @text = TkText.new(root) {
|                        width 60
|                        height 30
|                }
| 
|                scroll = TkScrollbar.new(root) {
!                        command proc { |*args| text.yview *args}
|                        pack('side' => 'right', 'fill' => 'y')
|                }


							matz.