Hi --

On Tue, 13 Aug 2002, Nikodemus Siivola wrote:

> def class_attr_reader name
>   eval <<-EOF
>   def self.class_#{name}
>     return @#{name}
>   end
>   EOF
> end
>
> class Parent
>   class_attr_reader :info
>   @info = "parent"
>   def initialize
>     puts "Parent 1: Initializing #{(self.class).class_info}"
>     puts "Parent 2: in #{Parent.class_info}"
>   end
> end
>
> class Daughter < Parent
>   @info = "daughter"
>   def initialize
>     puts Daughter.class_info
>
>     super
>   end
> end

It's probably better not to hardcode the class's name into its method,
in case there's a GrandDaughter some day :-)  You could do:

  puts type.class_info

or, if you move that up into Parent, you can just have:

  class Parent
    class_attr_reader :info
    @info = "parent"
    def initialize
      puts type.class_info
      puts "Parent 1: Initializing #{(self.class).class_info}"
      puts "Parent 2: in #{Parent.class_info}"
    end
  end

  class Daughter < Parent
    @info = "daughter"
  end

  class Son < Parent
    @info = "son"
  end


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav