Holden Glova wrote:
>I have never had an exposure to anything like mixins throughout my degree and 
>sadly am feeling quite lost, which I'm sure will pass with time and hopefully 
>the patience of the list as I ask silly questions about this topic.
>
>What I really don't understand is when do I use a module? How do I know that 
>I should have a class in this module that is to be "extended" from in it's 
>useage. What heuristics do you folks use? What patterns do you follow that 
>spark these design decisions?

Personally, I don't go looking for a reason to 
use modules. If/when I find something I want to 
do that is difficult, I try to find language 
support for making it easier. That's when I would 
turn to a module.

As someone else posted, modules serve multiple 
purposes. Two are probably the most common, so 
your understanding should start with those. Then, 
you can expand and invent your own uses.

1. Namespace, much like C++. It allows you to 
partition your code without worrying about 
colliding class names (or global/Kernel methods, 
global variables, etc.)

2. Mixins. I tried to find a good website that 
explains them, but was not able to. The pickaxe 
book has a reasonable discussion of them. 

A mixin is a chunk of functionality that you want 
to be usable by multiple classes. In a language 
like C++, you would have to use multiple-
inheritance to inherit from the common class. In 
Ruby, you can "mixin" the common functionality as 
a module. This is how Enumerable, Kernel, and 
Observable work, along with many others.

Let's say you wanted to add a debug logging 
method to several unrelated classes. The method 
is called log, and it figures out once where to 
send the log data, and after that it just sends 
it. Rather than inserting the same "def log..." 
code into each class, you can mix it in by 
creating a module that has the log method 
defined, and just including it into each class 
that you want to be able to log.

>P.S. Anyone give me a hint on what I should be looking for in order to create 
>and use the underscore in a Menu with GTK?

The full GTK+ seems to have a "factory" that 
allows you specify an underscore. It does not 
appear that Ruby/GTK wraps that.

If you can query a menu item to get its 
underlying label object, you can set up an 
underline mask for that label, according to the 
online GTK reference I use. I haven't tried it 
myself, yet, and I haven't checked to see if 
Ruby/GTK supports that.

Kevin