On Mon, Sep 29, 2008 at 11:36 PM, recursor <[EMAIL PROTECTED]> wrote:
> I want to do some things with a class outside my app block, but I cannot get 
> it to work. I even went so far as
> to copy the example given in http://help.shoooes.net/Rules.html under the 
> 'Block Redirection' section and try
> to use it:
>
>  class Messenger
>   def initialize(stack)
>     @stack = stack
>   end
>   def add(msg)
>     @stack.app do
>       @stack.append do
>         para msg
>       end
>     end
>   end
>  end
>
> ---snip-- (below is code that I added)
>
>  Shoes.app do
>    @msg = Messenger.new(stack)
>    button 'go' do
>            @msg.add "dy-no-mite"
>    end
>  end
>
> The 'add' method should retrieve the app object from the stack object, but 
> when I do an alert @stack.app.inspect, I get:
>
> (Shoes)
>
> and the @stack.append does not work.  Any thoughts?

Aha. So, after fully reading the Rules, I developed a theory that the
example shown there is all wrong because inside the app() block, self
is changed to your app, which has no @stack instance. Running your
sample code, that seems confirmed with the error "undefined method
'append' for nil:NilClass" shown in the console.

This works:

  class Messenger
    def initialize(stack)
      @stack = stack
    end

    def add(msg)
      @stack.app do
        @messages.append do
          para msg
        end
      end
    end
  end

  Shoes.app do
    @messages  = stack
    @messenger = Messenger.new @messages

    button "go" do
      @messenger.add "dy-no-mite"
    end
  end

-- 
Seth Thomas Rasmussen
http://greatseth.com

Reply via email to