"Szabolcs Szasz" <sz / szasz.hu> writes:

> Is there a reasonable replacement for '?' below?
> 
>     class Super
>         def initialize
>             sub = '?'    # something that yields obj.class
>             puts "Created for subclass #{sub}"
>         end
>     end

'type' returns the class of its receiver, so:

   class Super
     def initialize
       sub = type
       puts "Created for subclass #{sub}"
     end
   end

   class Sub < Super
   end

   obj = Super.new    #=> Created for subclass Super
   obj = Sub.new      #=> Created for subclass Sub


So can also use #class, but you have to be careful to call it with an
explicit receiver, or Ruby will think you're starting a class
definition.


Cheers


Dave