Say I have the following sort of app:
Shoes.app do
@i = 0
def add_button
button ("#{@i += 1}")
end
button("0") {add_button}
end
So that each time you click the button it adds a new button with a 开发者_如何学运维higher number. Is there any way to code it so that clicking one of the new buttons displays its number? Since self
always points to the app, the obvious approach
button ("#{@i += 1}") {alert @i}
Doesn't work, since then clicking any button just displays the current value of @i
.
Shoes.app do
@i = 0
def add_button
n = @i+1
button ("#{@i += 1}") {alert n}
end
button("0") {add_button}
end
精彩评论