Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Let Module#const_defined? check Object in 1.9 if search_parents is true #1624

Merged
merged 2 commits into from

2 participants

@fxn

In Ruby 1.9 Module#const_defined? checks the entire ancestors chain, and special-cases modules if search_parents is true. Reported in #1622.

@ileitch ileitch merged commit f5f8efe into rubinius:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
6 kernel/common/module19.rb
@@ -47,10 +47,14 @@ def const_defined?(name, search_parents=true)
if search_parents
current = self.direct_superclass
- while current and current != Object
+ while current
return true if current.constant_table.has_key? name
current = current.direct_superclass
end
+
+ if instance_of?(Module)
+ return true if Object.constant_table.has_key? name
+ end
end
return false
View
10 spec/ruby/core/module/const_defined_spec.rb
@@ -20,6 +20,16 @@
ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST10).should be_true
end
+ it "returns true if the constant is defined in Object and the receiver is a module" do
+ # CS_CONST1 is defined in Object
+ ConstantSpecs::ModuleA.const_defined?(:CS_CONST1).should be_true
+ end
+
+ it "returns true if the constant is defined in Object and the receiver is a class that has Object among its ancestors" do
+ # CS_CONST1 is defined in Object
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST1).should be_true
+ end
+
it "returns false if the constant is defined in the receiver's superclass and the inherit flag is false" do
ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, false).should be_false
end
Something went wrong with that request. Please try again.