Skip to content

Instantly share code, notes, and snippets.

@kronos
Created May 15, 2010 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kronos/402214 to your computer and use it in GitHub Desktop.
Save kronos/402214 to your computer and use it in GitHub Desktop.
diff --git a/kernel/common/module.rb b/kernel/common/module.rb
index cd463b8..fe15498 100644
--- a/kernel/common/module.rb
+++ b/kernel/common/module.rb
@@ -396,6 +396,8 @@ class Module
raise TypeError, "wrong argument type #{mod.class} (expected Module)"
end
+ return false if self.equal?(mod)
+
_each_ancestor { |m| return true if mod.equal?(m) }
false
diff --git a/spec/ruby/core/module/include_spec.rb b/spec/ruby/core/module/include_spec.rb
index 799226e..333d2b4 100644
--- a/spec/ruby/core/module/include_spec.rb
+++ b/spec/ruby/core/module/include_spec.rb
@@ -263,6 +263,10 @@ describe "Module#include?" do
ModuleSpecs::Basic.include?(ModuleSpecs::Super).should == false
end
+ it "returns false if given module is equal to self" do
+ ModuleSpecs.include?(ModuleSpecs).should == false
+ end
+
it "raises a TypeError when no module was given" do
lambda { ModuleSpecs::Child.include?("Test") }.should raise_error(TypeError)
lambda { ModuleSpecs::Child.include?(ModuleSpecs::Parent) }.should raise_error(TypeError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment