Is 'Class.new(Class)' valid?

nagachika e$B$H?=$7$^$9!#e(B

RHGe$B$N5U=1$K8~$1$Fe(B class.c e$B$rFI$s$G$$$F5$$,$D$$$?$N$G$9$,e(B
e$B!"e(B
class … end e$B9=J8$G%/%i%9$rDj5A$9$k>l9g$Oe(B superclass e$B$Ke(B
Class e$B$r;XDj$9$k$HNc30$,H/@8$7$^$9$,!"e(BClass.new e$B%a%=%C%Ie(B
e$B$Ge(B
e$B%/%i%[email protected]@.$9$k;~$K$Oe(B superclass(Class.new e$B$N0z?te(B)e$B$Ke(B
Class e$B$rEO$7$F$bNc30$K$J$j$^$;$s!#e(B
e$B$3$l$O0U?^E*$J$b$N$G$7$g$&$+e(B?

e$B$3$N$h$&$K$7$F$G$-$?!Ve(BClasse$B$N%5%V%/%i%9!W$d$=$l$re(B
e$B7Q>5$7$?%/%i%9$O%$%s%9%?%s%9$,@8@.$G$-$J$$$N$Ge(B
e$BIaDL$N%/%i%9$H$7$F$O;H$($J$$$H;W$&$N$G$9$,!“e(B
e$B2?$+FCJL$JMQES$,$”$k$s$G$7$g$&$+e(B?

e$B<B9T7k2Le(B
irb-trunk --simple-prompt

class Hoge < Class
end
TypeError: can’t make subclass of Class
from (irb):1
from irb-trunk:12:in `’

Hoge = Class.new(Class)
=> Hoge

Hoge.superclass
=> Class

Hoge.new
TypeError: wrong instance allocation
from (irb):5:in new' from (irb):5 from irb-trunk:12:in

e$B0U?^E*$G$J$$$J$i$3$s$J46$8$K$9$l$P$$$$$N$G$O$J$$$+$H!#e(B

Index: class.c

— class.c (e$B%j%S%8%g%se(B 15828)
+++ class.c (e$B:n6H%3%T!<e(B)
@@ -53,6 +53,9 @@
if (RBASIC(super)->flags & FL_SINGLETON) {
rb_raise(rb_eTypeError, “can’t make subclass of
singleton class”);
}

  • if (super == rb_cClass) {
  •   rb_raise(rb_eTypeError, "can't make subclass of
    

Class");

  • }
    }

VALUE
@@ -60,9 +63,6 @@
{
Check_Type(super, T_CLASS);
rb_check_inheritable(super);

  • if (super == rb_cClass) {
  •   rb_raise(rb_eTypeError, "can't make subclass of
    

Class");

  • }
    return rb_class_boot(super);
    }

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs