There appears to be a contrast between singleton classes of nil
, false
, true
and that of an instance of a custom made class.
i) The singleton class of nil
, false
, and true
are referred to by their assigned constant names:
nil.singleton_class #=> NilClass
false.singleton_class #=> FalseClass
true.singleton_class #=> TrueClass
ii) The singleton class of nil
, false
, and true
appear on ancestor lists:
nil.class.ancestors #=> [NilClass, Object, Kernel, BasicObject]
false.class.ancestors #=> [FalseClass, Object, Kernel, BasicObject]
true.class.ancestors #=> [TrueClass, Object, Kernel, BasicObject]
For the singleton class named AClass
of an instance a
of a custom class A
,
class A; end
a = A.new
AClass = a.singleton_class
i) AClass
is not referred to by its assigned constant name:
a.singleton_class #=> #<Class:#<A:0x00007fda832a7eb0>>
ii) AClass
does not appear on the ancestor list:
a.class.ancestors #=> [A, Object, Kernel, BasicObject]
Is this the expected behavior? What divides nil
, false
, true
on the one hand and a
on the other? What does this specification follow from?