I
Intransition
Do singleton classes not get the same namespace treatment as normal
classes?
module M
class X; end
end
o = Object.new
=> #<Object:0x7fc61f1a1e58>
(class << o; self; end).class_eval{ include M }
=> #<Object:0x7fc61f1a1e58>
def o.x; X; end
o.x
=> NameError: uninitialized constant X
from (irb):6:in `x'
from (irb):7
The "(class << o; self; end).class_eval{ include M }" is effectively
the same as "o.extend M" but I want to emphasize the use of #include.
It of course works fine if I use an explicit class.
class O
include M
def x; X; end
end
O.new.x
=> M::X
classes?
module M
class X; end
end
o = Object.new
=> #<Object:0x7fc61f1a1e58>
(class << o; self; end).class_eval{ include M }
=> #<Object:0x7fc61f1a1e58>
def o.x; X; end
o.x
=> NameError: uninitialized constant X
from (irb):6:in `x'
from (irb):7
The "(class << o; self; end).class_eval{ include M }" is effectively
the same as "o.extend M" but I want to emphasize the use of #include.
It of course works fine if I use an explicit class.
class O
include M
def x; X; end
end
O.new.x
=> M::X