aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--object.c3
-rw-r--r--spec/ruby/core/module/autoload_spec.rb1
-rw-r--r--test/ruby/test_autoload.rb6
3 files changed, 10 insertions, 0 deletions
diff --git a/object.c b/object.c
index 35f07d995d..00a70898f3 100644
--- a/object.c
+++ b/object.c
@@ -2694,16 +2694,19 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
if (!RTEST(recur)) {
if (!rb_const_defined_at(mod, id))
return Qfalse;
+ if (p == pend) return Qtrue;
mod = rb_const_get_at(mod, id);
}
else if (beglen == 0) {
if (!rb_const_defined(mod, id))
return Qfalse;
+ if (p == pend) return Qtrue;
mod = rb_const_get(mod, id);
}
else {
if (!rb_const_defined_from(mod, id))
return Qfalse;
+ if (p == pend) return Qtrue;
mod = rb_const_get_from(mod, id);
}
#endif
diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb
index 918eb61764..11d09cea22 100644
--- a/spec/ruby/core/module/autoload_spec.rb
+++ b/spec/ruby/core/module/autoload_spec.rb
@@ -449,6 +449,7 @@ describe "Module#autoload" do
it "does not load the file when accessing the constants table of the module" do
ModuleSpecs::Autoload.autoload :P, @non_existent
ModuleSpecs::Autoload.const_defined?(:P).should be_true
+ ModuleSpecs::Autoload.const_defined?("P").should be_true
end
it "loads the file when opening a module that is the autoloaded constant" do
diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb
index 34e0178d0e..d4e8f20899 100644
--- a/test/ruby/test_autoload.rb
+++ b/test/ruby/test_autoload.rb
@@ -42,8 +42,10 @@ p Foo::Bar
require 'tmpdir'
Dir.mktmpdir('autoload') {|tmpdir|
tmpfile = tmpdir + '/foo.rb'
+ tmpfile2 = tmpdir + '/bar.rb'
a = Module.new do
autoload :X, tmpfile
+ autoload :Y, tmpfile2
end
b = Module.new do
include a
@@ -52,6 +54,10 @@ p Foo::Bar
assert_equal(true, b.const_defined?(:X))
assert_equal(tmpfile, a.autoload?(:X), bug4565)
assert_equal(tmpfile, b.autoload?(:X), bug4565)
+ assert_equal(true, a.const_defined?("Y"))
+ assert_equal(true, b.const_defined?("Y"))
+ assert_equal(tmpfile2, a.autoload?("Y"))
+ assert_equal(tmpfile2, b.autoload?("Y"))
}
end