Created
February 27, 2011 04:17
-
-
Save myronmarston/845896 to your computer and use it in GitHub Desktop.
Demonstration of a weird bug in Ruby 1.9.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyModule | |
def some_method; super; end | |
end | |
class MyBaseClass; end | |
class MySubClass < MyBaseClass; | |
include MyModule | |
end | |
# To trigger this bug, we must include the module in the base class after | |
# the module has already been included in the subclass. If we move this line | |
# above the subclass declaration, this bug will not occur. | |
MyBaseClass.send(:include, MyModule) | |
MySubClass.new.some_method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ ruby --version | |
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10.6.0] | |
➜ ruby example.rb | |
example.rb:2:in `some_method': super: no superclass method `some_method' for #<MySubClass:0x1001bc2d0> (NoMethodError) | |
from example.rb:2:in `some_method' | |
from example.rb:13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ ruby --version | |
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0] | |
➜ ruby example.rb | |
example.rb:2: stack level too deep (SystemStackError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yuck!