TypeError: can't make subclass of Class

30 views
Skip to first unread message

John Merlino

unread,
Oct 6, 2012, 2:15:14 PM10/6/12
to Ruby on Rails: Talk
Why can't a class be an instance of class Class and also inherit from
class Class in ruby?


Let's say I defined a singleton method on Class:

1.9.3p0 :032 > class Class
1.9.3p0 :033?> def Class.class_singleton
1.9.3p0 :034?> puts 'class singleton'
1.9.3p0 :035?> end
1.9.3p0 :036?> end

And I want to create a class that can inherit that singleton method:

1.9.3p0 :039 > class Q < Class
1.9.3p0 :040?> end
TypeError: can't make subclass of Class

How then could it be possible to access that singleton method without
directly calling it on Class? And why is inheriting from Class not
allowed?
Reply all
Reply to author
Forward
0 new messages