From: Sean O'Halpin Date: 2011-03-07T00:49:16+09:00 Subject: Re: How to get class of BasicObject ancestor (Ruby 1.9.2)? On Sun, Mar 6, 2011 at 3:09 PM, Alexey Petrushin wrote: > There's no :class method on BasicObject, is there any way to get class > of it's ancestors? Here's one way: module DefineClass def self.included(other) other.class_eval { define_method :class do other end } end end class SO < BasicObject include ::DefineClass @@counter = 0 def initialize(*a, &b) super @@counter += 1 end def clone clone = self.class.new end def inspect "<#{self.class}: #{@@counter}>" end end s = SO.new p s.clone # => (I'm not a huge fan of @@class_variables in general - it's just here to make the point that there are two different instances.) Regards, Sean