Hi Karel,

It is a really nice solution. I think there is no single best way for using
Shoe objects in external classes. In my case, I also started with $app
because at that time inheritance from Widget was buggy but at the end I
wanted to have the possibility to use the methods available for Widgets
without rewriting them.
In your case, using classes with a module is probably optimal.

Thanks for posting your code, I personally learned a lot about Ruby from
reading it.

k

On Sun, Dec 14, 2008 at 7:45 AM, Karel Minařík <[email protected]>wrote:

> Hi,
>
> I also started with the global $app variable from the tank example, but
> needed some much much more cleaner way -- my code being an educational
> piece.
>
> Of course, for "standard GUI" elements like the popup menu example
> Krzysztof posted -- that's prime example for the inheritance solution.
>
> I didn't like to go the inheritance way in a simple game I did recently
> ("favor composition over inheritance" etc), so I came up with wrapping the
> Shoes object in a Canvas class:
>
> -->
> http://github.com/karmi/sheep_in_your_shoes/tree/master/sheep_in_your_shoes.rb#L21-30
>
> This way I can then write things like `Canvas.get.width` or `Canvas.draw {
> oval 0, 0, 15, 15 }`.
>
> I set the reference to canvas in the beginning of the `Shoes.app do ...
> end` block:
>
> -->
> http://github.com/karmi/sheep_in_your_shoes/tree/master/sheep_in_your_shoes.rb#L191
>
> So the different responsibility is separated into different classes.
>
> I'd be interested to know what you think about this approach.
>
>
> Karel
>
>
>
> On 14.12.2008, at 4:50, Alexander Rakoczy wrote:
>
>  Try designing your external files as modules, too, that get included
>> into your Shoes.app block.
>>
>> See:
>> http://help.shoooes.net/Rules.html
>>
>> And check out some of the apps in the shoebox.
>>
>> On Sat, Dec 13, 2008 at 21:05, Christopher Small
>> <[email protected]> wrote:
>>
>>>
>>> I did something similar to what you are describing without making a
>>> widget.
>>> I was storing the Shoes objects in class attributes of an outside class,
>>> but
>>> did all the creating and storing of these objects from within the
>>> Shoes.app
>>> block. For my application this was a pretty clean approach. If this would
>>> be
>>> messy for yours, then perhaps a widget is the way to go.
>>>
>>> Cheers
>>>
>>> Chris
>>>
>>>
>>>
>>> On Dec 13, 2008, at 4:47 PM, Jordan Applewhite wrote:
>>>
>>>  I'm trying to make a class that has an array of paras, stacks, or some
>>>> other Shoes object.  Then, I want to instantiate that class from the
>>>> file
>>>> that contains Shoes.app and append those elements to a slot therein.
>>>>  I'm
>>>> having a difficult time figuring out how to get my class to recognize
>>>> the
>>>> shoes objects and methods.  I've tried requiring different shoes source
>>>> files and using the $app variable found in the expert-tankspank.rb
>>>> sample
>>>> (is $app  part of the Ruby language or is it a Shoes construct?).  How
>>>> do
>>>> you use shoes elements in your classes outside of the main Shoes.app
>>>> file?
>>>>
>>>> I'm so very confused.  Halp!
>>>>
>>>> Thanks!
>>>>
>>>
>>>
>>>
>>
>>
>> --
>> alexander rakoczy
>>
>
>

Reply via email to