Ok. Got it. Many thanks. The use of "self" threw
for a moment. Always thought of that as an object.
But on reflection, it's clear that in a class definition,
it would refer to the class object.

On a related subject, what's going on with that
ERB program? Weirdest thing I ever saw. Why would
you define a Module inside of a Class, instead of
the other way 'round?


ara.t.howard / noaa.gov wrote:
> On Tue, 13 Jun 2006, Eric Armstrong wrote:
> 
>> This is pretty ridiculous, but I have tried
>> virtually every combination of class and module
>> definitions that I can think of, all without
>> success:
>>
>> I started with an old Post by Ara Howard:
>> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/193039
>>
>> module Foo
>>  class Main
>>    ...
>>  end
>> end
>> Foo::Main.run(ARGV, ENV) if __FILE__ == $0
> 
>   Foo::Main.new.run(ARGV, ENV) if __FILE__ == $0
>             ^^^
>             ^^^
>             ^^^
> 
>> Then I found the ERB program at
>> http://stuff.mit.edu/afs/sipb/project/ruby-lang/bin/erb
>>
>> That one reverses class & module:
>>
>> class ERB
>>  module Main
>>    def run
> 
>      def self.run
> 
>>      puts "Running"
>>    end
>>  end
>> end
>> Foo::Main.run if __FILE__ == $0
> 
> 
> 
>> What the heck is wrong with this picture?
>> (thanks in advance)
> 
> in both situations you are reversing the notion of class/module and 
> instance
> methods.  in the first case you call a class method when it should be an
> instance method, in the second you define an instance methods and then 
> try to
> call a class method.
> 
>   module M
>     def self.foo
>       'this is a class/module method'
>     end
>     def bar
>       'this is an instance method'
>     end
>   end
> 
> we can do
> 
>   M.foo
> 
>   class C
>     include M
>   end
> 
>   C.new.bar
> 
> 
> 
> alternatively we can have
> 
>   class C
>     def self.foo
>       'this is a class/module method'
>     end
>     def bar
>       'this is an instance method'
>     end
>   end
> 
> and do
> 
>   C.foo
> 
>   C.new.bar
> 
> make sense?
> 
> -a