aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-23 09:38:54 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-23 09:38:54 +0000
commita3e10f380ab276cc9192418d2a19c7e0ffc86046 (patch)
tree8e8606530db6687e552767ccf6299e17d8e4a164 /test/ruby
parent094d03c5d3bbbd9a68ff4f0d86bd988e29773da1 (diff)
downloadruby-a3e10f380ab276cc9192418d2a19c7e0ffc86046.tar.gz
* object.c (rb_obj_singleton_class): new method
Kernel#singleton_class. [ruby-core:21702] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_object.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index 0a49422074..63c1d32bef 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -561,4 +561,25 @@ class TestObject < Test::Unit::TestCase
end
end.call
end
+
+ def test_singleton_class
+ x = Object.new
+ xs = class << x; self; end
+ assert_equal(xs, x.singleton_class)
+
+ y = Object.new
+ ys = y.singleton_class
+ assert_equal(class << y; self; end, ys)
+
+ assert_equal(NilClass, nil.singleton_class)
+ assert_equal(TrueClass, true.singleton_class)
+ assert_equal(FalseClass, false.singleton_class)
+
+ assert_raise(TypeError) do
+ 123.singleton_class
+ end
+ assert_raise(TypeError) do
+ :foo.singleton_class
+ end
+ end
end