Skip to content

Instantly share code, notes, and snippets.

@jeremy
Created June 7, 2009 00:11
Show Gist options
  • Save jeremy/125071 to your computer and use it in GitHub Desktop.
Save jeremy/125071 to your computer and use it in GitHub Desktop.
# Including a module included in a superclass is ignored
>> module Foo; end
=> nil
>> class Numeric; include Foo; end
=> Numeric
>> Float.ancestors
=> [Float, Precision, Numeric, Foo, Comparable, Object, Kernel]
>> class Float; include Foo; end
=> Float
>> Float.ancestors
=> [Float, Precision, Numeric, Foo, Comparable, Object, Kernel]
# But reversing the order of inclusion works as expected
>> module Foo; end
=> nil
>> class Float; include Foo; end
=> Float
>> Float.ancestors
=> [Float, Foo, Precision, Numeric, Comparable, Object, Kernel]
>> class Numeric; include Foo; end
=> Numeric
>> Float.ancestors
=> [Float, Foo, Precision, Numeric, Foo, Comparable, Object, Kernel]
# And so does including a dupe of the module!
>> module Foo; end
=> nil
>> class Numeric; include Foo; end
=> Numeric
>> Float.ancestors
=> [Float, Precision, Numeric, Foo, Comparable, Object, Kernel]
>> class Float; include Foo.dup; end
=> Float
>> Float.ancestors
=> [Float, #<Module:0x19bcd40>, Precision, Numeric, Foo, Comparable, Object, Kernel]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment