On Mon, 16 Jan 2006 16:12:15 +0100, Tom Allison <tallison / tacocat.net>  
wrote:

> Daniel Harple wrote:
>>  On Jan 16, 2006, at 3:50 PM, Tom Allison wrote:
>>
>>> This is too simple to get wrong?
>>   You must require 'mathn'
>>  example:
>>  require 'mathn'
>>  6.lcm(7) # -> 42
>>  - Daniel
>>
>
> Thank you.  This is the first I've heard of mathn, even from the Integer  
> doc pages.  I missed it.
>
> Backing up....
>
> I was assuming that to include a module I would call the class name on  
> the assumption that the class name matches the class file (similar to  
> perl and java).  But this isn't the case with mathn.
>
> Doing some more poking about:
> ri has nothing known about mathn or anything like it.
> ri tells me that Integer.lcm is a real method.
> but to invoke this method on a Fixnum, I have to require a package name  
> that isn't mentioned in the lcm, Fixnu, or Integer docs.
>
> Granted, I found all this from the web pages for the standard library,  
> but it wasn't intuitive.  It doesn't even mention that mathn is  
> responsible for this lcm method.
>
> This is really frustrating.  Is the documentation wrong or did I just  
> miss something that every Ruby-ite should know?
>


Err. Mind the terms, including a module in Ruby is something VERY  
different from requiring a library.

Heavy spoonfeeding follows.

That said, a large majority of libraries are named according to the  
modules / classes defined in them. E.g.: A class named Toys::Fluffy::Teddy  
will be very probably defined in a file called "toys/fluffy/teddy.rb"  
relative to somewhere on your Ruby library path.

However, that is only a convention, and is not enforced. Some libraries,  
like "mathn", don't define any new modules or classes, but instead (ab)use  
the metaprogramming and reflective capacities of Ruby and modify existing  
modules / classes by defining new methods or changing the behaviour of  
existing ones.

ri only looks up information on modules, classes, and methods in whatever  
libraries were merged in your documentation, it doesn't know anything  
about libraries. The HTML backend to rdoc stores generally more  
information, like library synopses, source file names, and required files.  
Personally, I prefer only the Ruby core doeumentation available for ri,  
where problems with what required what when aren't an issue, and look up  
libraries on the web.

Anyways, if you're still confused about something - or more confused than  
before - feel free to bug.

David Vallner