Skip to content

Instantly share code, notes, and snippets.

@philr
Last active January 23, 2018 21:16
Show Gist options
  • Save philr/b22784c46411a5b79dc53e57011f80f2 to your computer and use it in GitHub Desktop.
Save philr/b22784c46411a5b79dc53e57011f80f2 to your computer and use it in GitHub Desktop.
Calling super from a method in an included module can invoke the wrong superclass (https://github.com/rubinius/rubinius/issues/3783)
module Extension
def strftime(format)
super('%Y')
end
end
class ExtendedTime < Time
include Extension
end
class ExtendedTime2 < Time
include Extension
end
class TestClass
def strftime(format)
"TestClass: #{format}"
end
end
class ExtendedTestClass < TestClass
include Extension
end
puts ExtendedTime.new(2018).strftime('x')
puts ExtendedTime2.new(2018).strftime('x')
3.times { puts ExtendedTestClass.new.strftime('x') }
2018
2018
TestClass: %Y
TestClass: %Y
main # Rubinius::Loader at core/loader.rb:852 (+90)
script # Rubinius::Loader at core/loader.rb:667 (+343)
load_script # Rubinius::CodeLoader at core/code_loader.rb:280 (+60)
load # Rubinius::CodeLoader::Source(Rubinius::CodeLoader::Script) at core/code_loader.rb:119 (+81)
run_script # Rubinius::CodeLoader::Source(Rubinius::CodeLoader::Script) at core/code_loader.rb:132 (+21)
__script__ # Object at rbx_strftime.rb:27 (+234)
times # Integer(Fixnum) at core/integer.rb:194 (+40)
{ } in __script__ # Object at rbx_strftime.rb:27 (+35)
strftime # Extension(ExtendedTestClass) at rbx_strftime.rb:3 (+7)
strftime # Time(ExtendedTestClass) at core/time.rb:40 (+12)
Time#strftime primitive failed (PrimitiveFailure)
An exception occurred running rbx_strftime.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment