我正在尝试扩展我已经编写的 Ruby 应用程序以使用 Shoes。我有一个已经编写好的类,我希望能够在该类中使用 GUI。也就是说,我希望我的班级有这样的东西:
class MyClass
def draw
# draw something using Shoes
end
end
当它想要绘制一些东西时,内部的另一个方法MyClass
会调用。draw()
我已经尝试过几种方法,但它们似乎都不起作用。我可以将整个班级包装在一个鞋子应用程序中。假设我想画一个椭圆:
Shoes.app {
class MyClass
def draw
oval :top => 100, :left => 100, :radius => 30
end
end
}
但后来它说undefined method 'oval' for MyClass
。
我也试过这个:
class MyClass
def draw
Shoes.app {
oval :top => 100, :left => 100, :radius => 30
}
end
end
这运行成功,但每次test()
调用它都会打开一个新窗口。
如何在实例方法中使用 Shoes 绘制东西?