diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-26 21:31:23 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-26 21:31:23 +0000 |
commit | 82af182e740bcb2a3aa1d9b2b62412f8ab28a8b1 (patch) | |
tree | e5d30034648aaa2aafedd671029c8e19834872fb /test | |
parent | 8ee4f0ad80720d38022b81b1cead87fe4c08f006 (diff) | |
download | ruby-82af182e740bcb2a3aa1d9b2b62412f8ab28a8b1.tar.gz |
* object.c (rb_mod_const_get): const_get accepts qualified constant
strings. e.g. Object.const_get("Foo::Bar::Baz") [ruby-core:41404]
* test/ruby/test_module.rb: tests for new behavior
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_module.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index db3f1fde3c..774139b9bc 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -245,6 +245,36 @@ class TestModule < Test::Unit::TestCase assert_equal(Math::PI, Math.const_get(:PI)) end + def test_nested_get + assert_equal Other, Object.const_get([self.class, Other].join('::')) + assert_equal User::USER, self.class.const_get([User, 'USER'].join('::')) + end + + def test_nested_get_symbol + const = [self.class, Other].join('::').to_sym + + assert_equal Other, Object.const_get(const) + assert_equal User::USER, self.class.const_get([User, 'USER'].join('::')) + end + + def test_nested_get_const_missing + classes = [] + klass = Class.new { + define_singleton_method(:const_missing) { |name| + classes << name + klass + } + } + klass.const_get("Foo::Bar::Baz") + assert_equal [:Foo, :Bar, :Baz], classes + end + + def test_nested_bad_class + assert_raises(TypeError) do + self.class.const_get([User, 'USER', 'Foo'].join('::')) + end + end + def test_const_set assert(!Other.const_defined?(:KOALA)) Other.const_set(:KOALA, 99) |