1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
shugo 2010-03-23 09:38:54 +00:00
parent 094d03c5d3
commit a3e10f380a
3 changed files with 50 additions and 0 deletions

View file

@ -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