Hi,

I am starting with Shoes and I have a basic question. It's about the
scope of variables, and what is self in the methods.
I've tried searching the net, I've read the 5-6 articles about shoes I
found but didn't have an answer for this.
I have this example:

class Test < Shoes
        url "/", :index
        url "/show", :show

        class << self
                attr_accessor :b
        end

        def index
                @a = "hello"
                Test.b =  "goodbye"
                button "Do" do
                        visit "/show"
                end             
        end
        
        def show
                alert("a is: [EMAIL PROTECTED]")
                alert("b is: #{Test.b}")
                alert("self is: #{self}")
        end     
end

Shoes.app :width => 100, :height => 100, :title => "Title"

The result is that when I click the button the alerts say:
a is:
b is: goodbye
self is: (Test)

I would have thought that @a would be available through different
invocations of urls,
but it seems not. So what is the preferred way of achieving this? I
have it working
with class instance variables (Test.b), but I'm not sure if there's a
better way.
Also an explanation about which instances of which objects are created would
probably help me understand what's going on here.

I have another question about layouts and all that, but I think I'll
send a separate email later.

Thanks,

Jesus.

Reply via email to