开发者

Storing Information in Stack/Flow Objects

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜