Hi,

At Sat, 15 Mar 2003 02:22:02 +0900,
Kent Dahl wrote:
> > Szymon Drejewicz wrote:
> > > a = MyObject.new
> > 
> > p(class << a; superclass; end)
> 
> Very nice.
> 
> Is there still a way to get the class if we do this even more crazy?
> 
> class MyObject
>   def self.new(*args)
>     obj = old_new(*args)
>     def obj.superclass
>     end
>   end
> end

This class makes nothing.

class MyObject
  def class
  end
  def type
  end
  def kind_of?(*args)
  end
  def self.===(*args)
  end
  def self.superclass
  end
  def self.ancestors
    []
  end
end
p a = MyObject.new
p(class << a; c=nil;ObjectSpace.each_object(Class) {|c|break if c>=self}; c; end)

However, you can override MyObject.>= and so on, of course.

-- 
Nobu Nakada