does anyone know if this can be relied upon?
cfp:~ > cat a.rb
class C
def singleton_class &b
sc =
class << self;
self
end
b ? sc.instance_eval(&b) : sc
end
def extend m
ancestors = [singleton_class.ancestors,
self.class.ancestors].flatten.uniq
super(ancestors.index(m) ? m.dup : m)
end
end
module A
def foo() ‘A’ end
end
module B
def foo() ‘B’ end
end
c = C.new
c.extend A
p c.foo
c.extend B
p c.foo
c.extend A
p c.foo
cfp:~ > ruby a.rb
“A”
“B”
“A”
??
-a