Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rubinius/rubinius
...
head fork: rubinius/rubinius
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
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

No commit comments for this range

Something went wrong with that request. Please try again.