Excellent!  Now I understand the double-colon operator.  All the posted
examples are great references, so thanks again to everybody.
Rubylearning.org seems like a great resource.  I'll definitely make use of
it.

2008/12/14 Krzysztof B. Wicher <[email protected]>

> If you need to use separate files, the following should work:
>
> WIDGET FILE, eg, mywidget.rb:
> class Shoes::Mywidget<<Shoes::Widget
> ....
> end
>
> MAIN FILE:
> require 'mywidget'
>
> Shoes.app do
> ...
> mywidget
> ...
> end
>
> Good luck and consider taking part in the Ruby programing with Shoes course
> at rubylearning.org
>
> K
>
> 2008/12/14 Jordan Applewhite <[email protected]>
>
> Hi again!  Thank you for taking the time to post these great tips.  I've
>> been experimenting with them, but I'm still hung up on something.
>>
>> If I want to define a class that inherits from Widget in a separate file,
>> what do I have to require or include to make the interpreter recognize
>> "Widget"?  If I want to make a class in a separate file that returns a para
>> for appending to an app block, what do I require or include in that file
>> that will allow me to define a method that uses para?  If Shoes were a
>> library, it seems that I would (require "shoes") or something, then start
>> instantiating objects.  Since shoes is more of a ruby distribution, this
>> process is a little unintuitive for me.
>>
>> I've searched the Shoebox, looked at the bundled examples, and checked the
>> manual, and I can't find a single example of a Shoes app that spans multiple
>> files.  Even the widget example on Hackety.org (Martin DeMello) uses a test
>> app at the bottom of the file.  I've been reading and rereading the Block
>> Redirection passage in the Rules section of the manual, but I can't glean
>> from that how to accomplish what I want.
>>
>> I'm probably missing something elementary and obvious, but I've spent my
>> coding time for the last few days stuck on this problem.  Isolating all
>> creation and manipulation of Shoes objects in the main app is a good
>> workaround, but it would be so helpful if I could store Widgets and shoesy
>> classes in separate files, sans Shoes.app block.  This would let me build a
>> toolkit of reusable components that are ready to be included and
>> instantiated in the Shoes app du jour.
>>
>> Thanks again.  As a Shoes newbie and hobby programmer, I appreciate your
>> patience and your thoughtful examples.
>>
>> On Sat, Dec 13, 2008 at 8:59 PM, Krzysztof B. Wicher 
>> <[email protected]>wrote:
>>
>>> The easiest way to do what you want is to write a class which inherits
>>> from Shoes::Widget and then you do not have to worry about  providing
>>> reference to the main Shoes.app class (using the global variable e.g.
>>> $app=self).
>>>
>>> class Myclass << Widget
>>> ...
>>> ....
>>> end
>>> Shoes.app do
>>> myclass ... #it is not an error - you do not start with a capital letter,
>>> since you are creating a widget you use it as e.g. rect, oval, float etc
>>> ...
>>> end
>>>
>>> Have a look on the latest version of my menu widget for the example (
>>> http://s3.amazonaws.com/shoes_code/public/versions/178/menu_widget.rb)
>>>
>>> Hope it helps.
>>>
>>> K
>>>
>>> On Sun, Dec 14, 2008 at 12:47 AM, Jordan Applewhite <
>>> [email protected]> 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!
>>>>
>>>
>>>
>>
>>
>> 2008/12/14 Karel Minařík <[email protected]>
>>
>> Thanks. Of course, it would be better if Sheep/Dog objects had their
>>> respective private `draw()` methods, but it would just clutter this concise
>>> code I guess, bringing no other value then purely academical.
>>>
>>>  Thanks for posting your code, I personally learned a lot about Ruby from
>>>> reading it.
>>>>
>>>
>>> That's great, thanks :)
>>>
>>> Karel
>>>
>>>
>>> On 14.12.2008, at 11:17, Krzysztof B. Wicher wrote:
>>>
>>>  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