>>>>> "Y" == Yukihiro Matsumoto <matz / ruby-lang.org> writes:

Y> First of all, if you put '-v' option to the interpeter, it warns you
Y> about class variables, that means it might not work as you expected.

 Well, you have at least this problem no ?

pigeon% cat b.rb
#!/usr/bin/ruby
class Gods
   @@rule = "Uranus"
   def ruler
      puts @@rule
   end

   class << self              # <= multiple method definition style    
      def ruler
         puts @@rule
      end
   end
end

module Olympians
   @@rule ="Zeus"
   def ruler
      puts @@rule
   end
end

class Titans < Gods
   @@rule = "Cronus"
   include Olympians
end

Atlas = Titans.new

Gods.new.ruler  # => Cronus
Gods.ruler         # => Cronus
Atlas.ruler         # => Zeus
Titans.ruler        # => Cronus <=  here is the difference


# extended example

def Atlas.ruler
   puts @@rule
   puts "#@@rule"
end

Atlas.ruler          # => Zeus
pigeon%
 
pigeon% b.rb
Cronus
Cronus
Zeus
Cronus
Zeus
./b.rb:39:in `ruler': uninitialized class variable @@rule in Object (NameError)
        from ./b.rb:42
pigeon% 


Guy Decoux