Forum: Ruby on Rails module inheritance and private methods

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5a287a2bae7fdcf36c8ea27174d959d2?d=identicon&s=25 Ari Kast (folkbaroque)
on 2009-01-25 00:44
I'm puzzling through the nuances of Ruby's module inclusion mechanism,
both inside and outside of Rails.

Forgive the long text, but the behavior is truly strange and I don't
know what to make of it.

I wrote some software that uses a 3rd party library (midilib) to convert
files from one format to another.  I wrote maybe ten classes for my
program, which I kept in a single directory, but I did not define a
module for my classes.  Everything works fine when I invoke my program
from command line, so next I wanted to put this conversion utility
online with Rails.

Putting this directory in /lib under rails and adding my dir to the
rails load paths worked fine and I'm able to deliver the converted
results via Rails.

Next I added a few user authentication methods and put them inside a
module and included this module in my Applications controller.  This
worked fine but caused my conversion utility to stop working.  Rails did
not seem able to find the classes referenced anymore.  So I bundled my
classes into a module, and this fixed Rails, but now it no longer works
on the command line -- it complains that one of the classes in the 3rd
party library I use is calling a one of its own private methods.  But my
code still works fine from Rails.  And even at the command line, it
mostly works because my checkpoint print statements are reached, but it
just chokes right at the end.  It's the exact same code in both cases.

So my manipulating my module boundaries it seems I can make my code
either work from Rails or from the command line, but not both.  Any idea
what's going on?

Is there any scenario in which a module definition around the calling
class might affect the behavior or visibility of a private method in the
included class?  I've literally spent days experimenting and trying to
understand this, but am not any closer to an answer.  My only conclusion
so far is that Ruby's scoping mechanisms are complex.

Any insights would be much appreciated.  Thanks in advance!
5a287a2bae7fdcf36c8ea27174d959d2?d=identicon&s=25 Ari Kast (folkbaroque)
on 2009-01-26 06:58
Embarrassed to admit that I solved my own problem, and it was not
related to modules, just a dumb error calling the wrong method from the
console version.

I suspected modules because prior to this I had spent several days
getting the modules right to make rails happy, so when this turned up I
thought it was still part of that original problem.

Thanks anyway...
This topic is locked and can not be replied to.