views:

280

answers:

1

This is a simple test Ruby Shoes program I am talking about: When I try to use the subclass syntax, like class Hello < Shoes and run my program, it complains 'undefined method para' or 'undefined method stack'. Obviously it is not able to subclass Shoes, hence does not know any thing about 'para' or 'stack' methods. However it runs fine, when I pass it as a block to Shoes.app, like Shoes app do.....

What could be the problem?

+3  A: 

Let me guess, you're trying to do something like this:

class MyClass < Shoes

  stack :width => 200 do
    subtitle 'People who like ponies'
    para 'TheTXI'
    para 'Pesto'
    para 'Einstein'
  end

  stack :width => -200 do
    subtitle 'People who hate ponies'
    para 'Hitler'
    para 'Stalin'
    para 'Einstein (He was bipolar)'
  end
end

Well of course this doesn't work. para, stack, subtitle, and so on are all instance methods, but you're trying to call them as class methods. They have to be inside an instance method, like this:

class MyClass < Shoes
  url '/', :pony_list

  def pony_list
    stack :width => 200 do
      subtitle 'People who like ponies'
        para 'TheTXI'
        para 'Pesto'
        para 'Einstein'
      end

      stack :width => -200 do
        subtitle 'People who hate ponies'
        para 'Hitler'
        para 'Stalin'
        para 'Einstein (He was bipolar)'
      end
    end
  end

  Shoes.app :width => 400

See how that stuff is in the pony_list method now? Of course, we have to make an instance call the method. How can we do that? That's why we call the url method (which, unlike para and its friends, actually is a class method). It sets the default url to call the pony_list method. Remember that you have to call Shoes.app after your class definition and you're all set.

Pesto
That was it. Thanks for the explanation. I know I must be doing something stupid. In the example in 'Nobody Knows Shoes' book, he talks about using url method when splitting the app into multiple pages, but I was not sure if I need to use the url method in very simple example, like mine. Looks like I will have to, anytime I want to subclass the Shoes class(and use methods like para, stack etc).
sunjain