A
Andy Bogdanov
# First I create a proc:
p = proc {
self::X = Class.new
def self.X
X.new
end
}
# Then I create a module:
A = Module.new(&p)
puts A.X # => #<A::X:0x9c2e774>
# Then i create another module:
B = Module.new(&p)
puts B.X # => #<B::X:0x9c39304>
# Everything seems to be ok.
# And now to the strange part.
# After module B was created A.X started to return instances of B::X
puts A.X # => #<B::X:0x9c38238>
If more modules are created with the same proc method X returns
instances of X from the last created module. If I use "self::X.new"
instead of "X.new" everything works as expected, but I can't understand
why it works like that with "X.new". Is this a bug or it's supposed to
be this way?
p = proc {
self::X = Class.new
def self.X
X.new
end
}
# Then I create a module:
A = Module.new(&p)
puts A.X # => #<A::X:0x9c2e774>
# Then i create another module:
B = Module.new(&p)
puts B.X # => #<B::X:0x9c39304>
# Everything seems to be ok.
# And now to the strange part.
# After module B was created A.X started to return instances of B::X
puts A.X # => #<B::X:0x9c38238>
If more modules are created with the same proc method X returns
instances of X from the last created module. If I use "self::X.new"
instead of "X.new" everything works as expected, but I can't understand
why it works like that with "X.new". Is this a bug or it's supposed to
be this way?