Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demonstration of a weird bug in Ruby 1.9.
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
➜ 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
➜ 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)
@ewollesen

This comment has been minimized.

Show comment
Hide comment
@ewollesen

ewollesen Mar 28, 2013

UGH, just spent WAAAY too much time debugging this bug myself while upgrading some code to ruby 1.9.

As a note for those using rspec < 2.6, a workaround is to use the syck YAML parser instead of psych, which is a new default in ruby 1.9. If you can upgrade your rspec version, that's definitely the best way, as syck has issues of its own.

ewollesen commented Mar 28, 2013

UGH, just spent WAAAY too much time debugging this bug myself while upgrading some code to ruby 1.9.

As a note for those using rspec < 2.6, a workaround is to use the syck YAML parser instead of psych, which is a new default in ruby 1.9. If you can upgrade your rspec version, that's definitely the best way, as syck has issues of its own.

@ewollesen

This comment has been minimized.

Show comment
Hide comment
@ewollesen

ewollesen Mar 28, 2013

Oh yeah, it's apparently slated to be fixed in 1.9.4.

http://bugs.ruby-lang.org/issues/3351

ewollesen commented Mar 28, 2013

Oh yeah, it's apparently slated to be fixed in 1.9.4.

http://bugs.ruby-lang.org/issues/3351

@canadaduane

This comment has been minimized.

Show comment
Hide comment
@canadaduane

canadaduane commented Mar 28, 2013

Yuck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment