From: merch-redmine@... Date: 2016-05-14T07:18:01+00:00 Subject: [ruby-core:75501] [Ruby trunk Feature#12380] `Struct` as a subclass of `Class` Issue #12380 has been updated by Jeremy Evans. Tsuyoshi Sawada wrote: > I propose that either `Struct` should be redefined as a subclass of `Class`, or a new class `StructClass` should be introduced as a subclass of `Class`, and take over the functionality of `Struct`. You can't subclass Class in ruby: ~~~ $ ruby -e 'Class.new(Class)' -e:1:in `initialize': can't make subclass of Class (TypeError) ~~~ I guess it is counter-intuitive that Struct.new creates a subclass of the receiver instead of an instance of the receiver, but do you think there would be any practical benefits to changing things? If I had to guess, the reason that Struct is not a subclass of Class is that you can't subclass Class, maybe because allowing subclasses of Class would cause problems in the object model? ---------------------------------------- Feature #12380: `Struct` as a subclass of `Class` https://bugs.ruby-lang.org/issues/12380#change-58617 * Author: Tsuyoshi Sawada * Status: Open * Priority: Normal * Assignee: ---------------------------------------- This issue is somewhat of the same flavor as #12374. `Struct` has a constructor that creates a class: ~~~ruby Struct.new(:foo) # => # ~~~ and this is the same situation with `Class`. ~~~ruby Class.new # => # ~~~ Hence, most naturally, `Struct` should be a subclass of `Class`. But in reality, it isn't: ~~~ruby Struct.ancestors # => [Struct, Enumerable, Object, Kernel, BasicObject] ~~~ The current structure around `Struct` is counter-intuitive to me. I propose that either `Struct` should be redefined as a subclass of `Class`, or a new class `StructClass` should be introduced as a subclass of `Class`, and take over the functionality of `Struct`. -- https://bugs.ruby-lang.org/ Unsubscribe: