Skip to content

Instantly share code, notes, and snippets.

@rsutphin
Created March 31, 2010 14:13
Show Gist options
  • Save rsutphin/350357 to your computer and use it in GitHub Desktop.
Save rsutphin/350357 to your computer and use it in GitHub Desktop.
MRI 1.8.x quirk with alias and super for included modules
module A
def foo
"a"
end
alias bar foo
end
module B
def foo
"#{super} b"
end
alias bar foo
end
class C
include A
end
puts "With just A"
puts "foo: #{C.new.foo}"
puts "bar: #{C.new.bar}"
puts
class C
include B
end
puts "With A and B"
puts "foo: #{C.new.foo}"
puts "bar: #{C.new.bar}"
$ rvm 1.8.7,1.9.1,jruby ruby module_super_with_alias.rb
ruby-1.8.7-p249: ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin9.8.0]
With just A
foo: a
bar: a
With A and B
foo: a b
module_super_alias.rb:11:in `bar': super: no superclass method `foo' for #<C:0x1297c4> (NoMethodError)
from module_super_alias.rb:32
ruby-1.9.1-p378: ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin9.8.0]
With just A
foo: a
bar: a
With A and B
foo: a b
bar: a b
jruby-1.4.0: jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) Client VM 1.5.0_22) [i386-java]
With just A
foo: a
bar: a
With A and B
foo: a b
bar: a b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment