Forum: Ruby Strange constant resolution behaviour after Class#dup

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Martin T. (Guest)
on 2009-02-14 23:08
Hello,

the following code produces different results when executed with Ruby
1.8.6 on Windows and Fedora 9:

class A
  def call_b_with_dup
    B.dup.new.b
  end
  def call_b_without_dup
    B.new.b
  end
end

class B
  def b
    XXX
  end
end

begin
  A.new.call_b_with_dup
rescue Exception => e
  puts e
end

begin
  A.new.call_b_without_dup
rescue Exception => e
  puts e
end

*** Results ***

Windows:

uninitialized constant B::XXX
uninitialized constant B::XXX

Fedora 9:

uninitialized constant A::XXX
uninitialized constant B::XXX


Whats the correct behaviour? I suppose the first one and the second is a
bug.
If so, is this bug already known?

Thanks,

Martin
This topic is locked and can not be replied to.