From: "eLobato (Daniel Lobato Garcia)" Date: 2013-05-12T17:41:34+09:00 Subject: [ruby-core:54927] [ruby-trunk - Feature #8393] A class who's parent class is in a module can go wrong if files are required in the wrong order Issue #8393 has been updated by eLobato (Daniel Lobato Garcia). jeremyevans0: That's what I did when I found a problem caused by this on production code. Nonetheless you have to take into account that sometimes the order of the requires is not something you control. nobu: In order to get these results, create the files, open IRB and run: > require 'animal.rb' > require 'dog.rb' > require 'bark.rb' > Bark::Dog.new.bark fuck. <--- This should be woof because Bark::Dog should inherit from Bark::Animal. Let me know if I am missing anything. ---------------------------------------- Feature #8393: A class who's parent class is in a module can go wrong if files are required in the wrong order https://bugs.ruby-lang.org/issues/8393#change-39268 Author: eLobato (Daniel Lobato Garcia) Status: Feedback Priority: Normal Assignee: Category: Target version: Hi, I have found that inheritance is not done properly in a certain case. Let's say we have the following files: -------------- animal.rb - class Animal def bark puts 'fuck.' end end dog.rb - module Bark class Dog < Animal end end bark.rb - module Bark class Animal def bark puts 'woof' end end end ------------ If these files are required in that order (or any order where Bark::Animal is not required before Animal), Bark::Dog.new.bark will output "fuck.", showing the inheritance was done wrong, because in the case that there are two classes from which it can inherit (Animal and Bark::Animal), it should inherit from the class inside its module (Bark). A workaround for this is defining Dog as Dog < Bark::Animal, that forces Dog to use the correct Animal class. I found this on the latest 1.8.7, 1.9.2, 1.9.3 and 2.0.0dev, both using rvm and without using it. I could not find information about this on the issue tracker or on Google. In my opinion a way to fix this is to check when a file is required if any of our current files could inherit from something in a module of the file that is imported, but that looks like it can be complicated with nested modules, etc.. so I'm all ears for better design decisions. I would like to fix this myself as my first Ruby core contribution, but I was unsure if this is an actual bug. To me it looks like this behavior is totally unexpected, let me know if anything is wrong here. Thanks! -- http://bugs.ruby-lang.org/