Here is a module containing some methods:
module M
def x; y; end
def y; ...; end
end
Here’s a class:
class C
def z; ...; end
end
I have two instances of C:
c1 = C.new
c2 = C.new
Is there something I can do to c1 such that c1.class has x and y, but c2.class doesn’t? I don’t see a straightforward way to subvert the method lookup.
You could override
c1.classto return something other than C (and that other thing would extend M). Other than that, no.Note that overriding
c1.classis almost certainly a bad idea. An object shouldn’t lie about what its class is.