John Wilger
2/19/2008 1:39:00 PM
On Feb 18, 11:43 pm, Leslie Viljoen <leslievilj...@gmail.com> wrote:
> Hello!
>
> I am having a hard time using modules. It seems that to successfully
> use one, you
> need to know all sorts of obscure things about the environment that
> the module expects.
>
> For example, I want to use Webby::Helpers::UrlHelper. This module
> refers to a @pages
> variable that I have to provide in the class that "include"s the
> module. That is not so
> hard, but I can only find that requirement via experimentation. If I
> provide the @pages
> variable in my class
This, honestly is a sign of bad design. Modules should be designed so
that the including class only needs to define a few--if any--methods to
be used by that module, and they should be clearly documented in the
module. Accessing instance variables that are not "owned" by the
module is just asking for trouble. No, I don't think /you're/ doing
something wrong--your just running into a poorly designed module.
> There's a similar problem with calling *any* methods that take
> parameters in Ruby -
> how can you get a list of all the methods that will be applied to the
> object you passed
> in?
Other than by looking at the code, you can't, really. I suppose you
could always pass in some sort of "recorder" object to list out the
method calls, but I'm not sure the returns would be worth it in most
cases. Honestly, this is where a good automated test suite will help
you. Just verify in your tests that whatever kind of object you're
actually going to pass in doesn't cause any errors.
--
Regards,
John Wilger