Hi, gotoken,

In [ruby-talk:00452] Re: Now another totally different ;-)
gotoken / math.sci.hokudai.ac.jp (GOTO Kentaro) wrote:

> By the way, Matz, why the following doesn't print "b\n" but 10?
> 
> module Indexed
>   def [](n)
>     to_a[n]
>   end
> end
> 
> class String
>   include Indexed
> end
> 
> if __FILE__
>   p "abcdefg".gsub(/./,"\\&\n")[1]
> end

"p String.ancestors" gives [String, Indexed, Enumerable, Comparable,
Object, Kernel].
That means that the module Indexed is a Mix-in, such as a superclass,
and the method [] is first searched in String.  This is added to
RubyFAQ.

                          Though this is not the subject, I know.
-- 
Akira Endo, akendo / t3.rim.or.jp