Ruby  2.0.0p648(2015-12-16revision53162)
class.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  class.c -
4 
5  $Author: usa $
6  created at: Tue Aug 10 15:05:44 JST 1993
7 
8  Copyright (C) 1993-2007 Yukihiro Matsumoto
9 
10 **********************************************************************/
11 
26 #include "ruby/ruby.h"
27 #include "ruby/st.h"
28 #include "method.h"
29 #include "constant.h"
30 #include "vm_core.h"
31 #include "internal.h"
32 #include <ctype.h>
33 
34 extern st_table *rb_class_tbl;
35 static ID id_attached;
36 
49 static VALUE
50 class_alloc(VALUE flags, VALUE klass)
51 {
52  NEWOBJ_OF(obj, struct RClass, klass, flags);
53  obj->ptr = ALLOC(rb_classext_t);
54  RCLASS_IV_TBL(obj) = 0;
55  RCLASS_CONST_TBL(obj) = 0;
56  RCLASS_M_TBL(obj) = 0;
57  RCLASS_SUPER(obj) = 0;
58  RCLASS_ORIGIN(obj) = (VALUE)obj;
59  RCLASS_IV_INDEX_TBL(obj) = 0;
61  RCLASS_EXT(obj)->allocator = 0;
62  return (VALUE)obj;
63 }
64 
65 
75 VALUE
77 {
79 
80  RCLASS_SUPER(klass) = super;
81  RCLASS_M_TBL(klass) = st_init_numtable();
82 
83  OBJ_INFECT(klass, super);
84  return (VALUE)klass;
85 }
86 
87 
94 void
96 {
97  if (!RB_TYPE_P(super, T_CLASS)) {
98  rb_raise(rb_eTypeError, "superclass must be a Class (%s given)",
99  rb_obj_classname(super));
100  }
101  if (RBASIC(super)->flags & FL_SINGLETON) {
102  rb_raise(rb_eTypeError, "can't make subclass of singleton class");
103  }
104  if (super == rb_cClass) {
105  rb_raise(rb_eTypeError, "can't make subclass of Class");
106  }
107 }
108 
109 
116 VALUE
118 {
119  Check_Type(super, T_CLASS);
120  rb_check_inheritable(super);
121  return rb_class_boot(super);
122 }
123 
124 static void
125 clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
126 {
127  VALUE newiseqval;
128  if (me->def && me->def->type == VM_METHOD_TYPE_ISEQ) {
129  rb_iseq_t *iseq;
130  NODE *new_cref;
131  newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass);
132  GetISeqPtr(newiseqval, iseq);
133  rb_vm_rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass, &new_cref);
134  iseq->cref_stack = new_cref;
135  rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
136  RB_GC_GUARD(newiseqval);
137  }
138  else {
139  rb_method_entry_set(klass, mid, me, me->flag);
140  }
141 }
142 
143 static int
145 {
146  clone_method((VALUE)data, (ID)key, (const rb_method_entry_t *)value);
147  return ST_CONTINUE;
148 }
149 
150 static int
152 {
154  *nce = *ce;
155  st_insert(tbl, key, (st_data_t)nce);
156  return ST_CONTINUE;
157 }
158 
159 static int
161 {
162  return clone_const((ID)key, (const rb_const_entry_t *)value, (st_table *)data);
163 }
164 
165 static void
167 {
168  if (orig == rb_cBasicObject) {
169  rb_raise(rb_eTypeError, "can't copy the root class");
170  }
171  if (RCLASS_SUPER(clone) != 0 || clone == rb_cBasicObject) {
172  rb_raise(rb_eTypeError, "already initialized class");
173  }
174  if (FL_TEST(orig, FL_SINGLETON)) {
175  rb_raise(rb_eTypeError, "can't copy singleton class");
176  }
177 }
178 
179 /* :nodoc: */
180 VALUE
182 {
183  if (RB_TYPE_P(clone, T_CLASS)) {
184  class_init_copy_check(clone, orig);
185  }
186  if (!OBJ_INIT_COPY(clone, orig)) return clone;
187  if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
188  RBASIC(clone)->klass = rb_singleton_class_clone(orig);
189  rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
190  }
191  RCLASS_SUPER(clone) = RCLASS_SUPER(orig);
192  RCLASS_EXT(clone)->allocator = RCLASS_EXT(orig)->allocator;
193  if (RCLASS_IV_TBL(clone)) {
195  RCLASS_IV_TBL(clone) = 0;
196  }
197  if (RCLASS_CONST_TBL(clone)) {
199  RCLASS_CONST_TBL(clone) = 0;
200  }
201  if (RCLASS_M_TBL(clone)) {
203  RCLASS_M_TBL(clone) = 0;
204  }
205  if (RCLASS_IV_TBL(orig)) {
206  st_data_t id;
207 
208  RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(orig));
209  CONST_ID(id, "__tmp_classpath__");
210  st_delete(RCLASS_IV_TBL(clone), &id, 0);
211  CONST_ID(id, "__classpath__");
212  st_delete(RCLASS_IV_TBL(clone), &id, 0);
213  CONST_ID(id, "__classid__");
214  st_delete(RCLASS_IV_TBL(clone), &id, 0);
215  }
216  if (RCLASS_CONST_TBL(orig)) {
217 
220  }
221  if (RCLASS_M_TBL(orig)) {
222  RCLASS_M_TBL(clone) = st_init_numtable();
224  }
225 
226  return clone;
227 }
228 
229 VALUE
231 {
233 }
234 
235 VALUE
237 {
238  VALUE klass = RBASIC(obj)->klass;
239 
240  if (!FL_TEST(klass, FL_SINGLETON))
241  return klass;
242  else {
243  /* copy singleton(unnamed) class */
244  VALUE clone = class_alloc(RBASIC(klass)->flags, 0);
245 
246  if (BUILTIN_TYPE(obj) == T_CLASS) {
247  RBASIC(clone)->klass = clone;
248  }
249  else {
250  RBASIC(clone)->klass = rb_singleton_class_clone(klass);
251  }
252 
253  RCLASS_SUPER(clone) = RCLASS_SUPER(klass);
254  RCLASS_EXT(clone)->allocator = RCLASS_EXT(klass)->allocator;
255  if (RCLASS_IV_TBL(klass)) {
256  RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(klass));
257  }
258  if (RCLASS_CONST_TBL(klass)) {
261  }
262  if (attach != Qundef) {
263  rb_singleton_class_attached(clone, attach);
264  }
265  RCLASS_M_TBL(clone) = st_init_numtable();
267  rb_singleton_class_attached(RBASIC(clone)->klass, clone);
268  FL_SET(clone, FL_SINGLETON);
269  return clone;
270  }
271 }
272 
277 void
279 {
280  if (FL_TEST(klass, FL_SINGLETON)) {
281  if (!RCLASS_IV_TBL(klass)) {
282  RCLASS_IV_TBL(klass) = st_init_numtable();
283  }
284  st_insert(RCLASS_IV_TBL(klass), id_attached, obj);
285  }
286 }
287 
288 
289 
290 #define METACLASS_OF(k) RBASIC(k)->klass
291 
297 #define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k))
298 
304 #define HAVE_METACLASS_P(k) \
305  (FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \
306  rb_ivar_get(METACLASS_OF(k), id_attached) == (k))
307 
315 #define ENSURE_EIGENCLASS(klass) \
316  (HAVE_METACLASS_P(klass) ? METACLASS_OF(klass) : make_metaclass(klass))
317 
318 
328 static inline VALUE
330 {
331  VALUE super;
332  VALUE metaclass = rb_class_boot(Qundef);
333 
334  FL_SET(metaclass, FL_SINGLETON);
335  rb_singleton_class_attached(metaclass, klass);
336 
337  if (META_CLASS_OF_CLASS_CLASS_P(klass)) {
338  METACLASS_OF(klass) = METACLASS_OF(metaclass) = metaclass;
339  }
340  else {
341  VALUE tmp = METACLASS_OF(klass); /* for a meta^(n)-class klass, tmp is meta^(n)-class of Class class */
342  METACLASS_OF(klass) = metaclass;
343  METACLASS_OF(metaclass) = ENSURE_EIGENCLASS(tmp);
344  }
345 
346  super = RCLASS_SUPER(klass);
347  while (RB_TYPE_P(super, T_ICLASS)) super = RCLASS_SUPER(super);
348  RCLASS_SUPER(metaclass) = super ? ENSURE_EIGENCLASS(super) : rb_cClass;
349 
350  OBJ_INFECT(metaclass, RCLASS_SUPER(metaclass));
351 
352  return metaclass;
353 }
354 
361 static inline VALUE
363 {
364  VALUE orig_class = RBASIC(obj)->klass;
365  VALUE klass = rb_class_boot(orig_class);
366 
367  FL_SET(klass, FL_SINGLETON);
368  RBASIC(obj)->klass = klass;
369  rb_singleton_class_attached(klass, obj);
370 
371  METACLASS_OF(klass) = METACLASS_OF(rb_class_real(orig_class));
372  return klass;
373 }
374 
375 
376 static VALUE
377 boot_defclass(const char *name, VALUE super)
378 {
379  extern st_table *rb_class_tbl;
380  VALUE obj = rb_class_boot(super);
381  ID id = rb_intern(name);
382 
383  rb_name_class(obj, id);
384  st_add_direct(rb_class_tbl, id, obj);
385  rb_const_set((rb_cObject ? rb_cObject : obj), id, obj);
386  return obj;
387 }
388 
389 void
391 {
392  id_attached = rb_intern("__attached__");
393 
394  rb_cBasicObject = boot_defclass("BasicObject", 0);
396  rb_cModule = boot_defclass("Module", rb_cObject);
397  rb_cClass = boot_defclass("Class", rb_cModule);
398 
400  RBASIC(rb_cClass)->klass
401  = RBASIC(rb_cModule)->klass
402  = RBASIC(rb_cObject)->klass
403  = RBASIC(rb_cBasicObject)->klass
404  = rb_cClass;
405 }
406 
407 
418 VALUE
420 {
421  if (BUILTIN_TYPE(obj) == T_CLASS) {
422  return make_metaclass(obj);
423  }
424  else {
425  return make_singleton_class(obj);
426  }
427 }
428 
429 
440 VALUE
442 {
443  VALUE klass;
444 
445  if (!super) super = rb_cObject;
446  klass = rb_class_new(super);
447  rb_make_metaclass(klass, RBASIC(super)->klass);
448 
449  return klass;
450 }
451 
452 
461 VALUE
463 {
464  ID inherited;
465  if (!super) super = rb_cObject;
466  CONST_ID(inherited, "inherited");
467  return rb_funcall(super, inherited, 1, klass);
468 }
469 
470 
471 
487 VALUE
488 rb_define_class(const char *name, VALUE super)
489 {
490  VALUE klass;
491  ID id;
492 
493  id = rb_intern(name);
494  if (rb_const_defined(rb_cObject, id)) {
495  klass = rb_const_get(rb_cObject, id);
496  if (!RB_TYPE_P(klass, T_CLASS)) {
497  rb_raise(rb_eTypeError, "%s is not a class", name);
498  }
499  if (rb_class_real(RCLASS_SUPER(klass)) != super) {
500  rb_raise(rb_eTypeError, "superclass mismatch for class %s", name);
501  }
502  return klass;
503  }
504  if (!super) {
505  rb_warn("no super class for `%s', Object assumed", name);
506  }
507  klass = rb_define_class_id(id, super);
508  st_add_direct(rb_class_tbl, id, klass);
509  rb_name_class(klass, id);
510  rb_const_set(rb_cObject, id, klass);
511  rb_class_inherited(super, klass);
512 
513  return klass;
514 }
515 
516 
533 VALUE
534 rb_define_class_under(VALUE outer, const char *name, VALUE super)
535 {
536  return rb_define_class_id_under(outer, rb_intern(name), super);
537 }
538 
539 
556 VALUE
558 {
559  VALUE klass;
560 
561  if (rb_const_defined_at(outer, id)) {
562  klass = rb_const_get_at(outer, id);
563  if (!RB_TYPE_P(klass, T_CLASS)) {
564  rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
565  }
566  if (rb_class_real(RCLASS_SUPER(klass)) != super) {
567  rb_name_error(id, "%s is already defined", rb_id2name(id));
568  }
569  return klass;
570  }
571  if (!super) {
572  rb_warn("no super class for `%s::%s', Object assumed",
573  rb_class2name(outer), rb_id2name(id));
574  }
575  klass = rb_define_class_id(id, super);
576  rb_set_class_path_string(klass, outer, rb_id2str(id));
577  rb_const_set(outer, id, klass);
578  rb_class_inherited(super, klass);
580 
581  return klass;
582 }
583 
584 VALUE
586 {
588 
590 
591  return (VALUE)mdl;
592 }
593 
594 VALUE
596 {
597  VALUE mdl;
598 
599  mdl = rb_module_new();
600  rb_name_class(mdl, id);
601 
602  return mdl;
603 }
604 
605 VALUE
606 rb_define_module(const char *name)
607 {
608  VALUE module;
609  ID id;
610 
611  id = rb_intern(name);
612  if (rb_const_defined(rb_cObject, id)) {
613  module = rb_const_get(rb_cObject, id);
614  if (RB_TYPE_P(module, T_MODULE))
615  return module;
616  rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module));
617  }
618  module = rb_define_module_id(id);
619  st_add_direct(rb_class_tbl, id, module);
620  rb_const_set(rb_cObject, id, module);
621 
622  return module;
623 }
624 
625 VALUE
626 rb_define_module_under(VALUE outer, const char *name)
627 {
628  return rb_define_module_id_under(outer, rb_intern(name));
629 }
630 
631 VALUE
633 {
634  VALUE module;
635 
636  if (rb_const_defined_at(outer, id)) {
637  module = rb_const_get_at(outer, id);
638  if (RB_TYPE_P(module, T_MODULE))
639  return module;
640  rb_raise(rb_eTypeError, "%s::%s is not a module",
641  rb_class2name(outer), rb_obj_classname(module));
642  }
643  module = rb_define_module_id(id);
644  rb_const_set(outer, id, module);
645  rb_set_class_path_string(module, outer, rb_id2str(id));
647 
648  return module;
649 }
650 
651 VALUE
653 {
655 
656  if (BUILTIN_TYPE(module) == T_ICLASS) {
657  module = RBASIC(module)->klass;
658  }
659  if (!RCLASS_IV_TBL(module)) {
660  RCLASS_IV_TBL(module) = st_init_numtable();
661  }
662  if (!RCLASS_CONST_TBL(module)) {
664  }
665  RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
666  RCLASS_CONST_TBL(klass) = RCLASS_CONST_TBL(module);
667  RCLASS_M_TBL(klass) = RCLASS_M_TBL(RCLASS_ORIGIN(module));
668  RCLASS_SUPER(klass) = super;
669  if (RB_TYPE_P(module, T_ICLASS)) {
670  RBASIC(klass)->klass = RBASIC(module)->klass;
671  }
672  else {
673  RBASIC(klass)->klass = module;
674  }
675  OBJ_INFECT(klass, module);
676  OBJ_INFECT(klass, super);
677 
678  return (VALUE)klass;
679 }
680 
681 static int include_modules_at(const VALUE klass, VALUE c, VALUE module);
682 
683 void
685 {
686  int changed = 0;
687 
688  rb_frozen_class_p(klass);
689  if (!OBJ_UNTRUSTED(klass)) {
690  rb_secure(4);
691  }
692 
693  if (!RB_TYPE_P(module, T_MODULE)) {
694  Check_Type(module, T_MODULE);
695  }
696 
697  OBJ_INFECT(klass, module);
698 
699  changed = include_modules_at(klass, RCLASS_ORIGIN(klass), module);
700  if (changed < 0)
701  rb_raise(rb_eArgError, "cyclic include detected");
702  if (changed) rb_clear_cache();
703 }
704 
705 static int
707 {
709  return ST_CONTINUE;
710 }
711 
712 static int
713 include_modules_at(const VALUE klass, VALUE c, VALUE module)
714 {
715  VALUE p;
716  int changed = 0;
717  const st_table *const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass));
718 
719  while (module) {
720  int superclass_seen = FALSE;
721 
722  if (RCLASS_ORIGIN(module) != module)
723  goto skip;
724  if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module))
725  return -1;
726  /* ignore if the module included already in superclasses */
727  for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
728  switch (BUILTIN_TYPE(p)) {
729  case T_ICLASS:
730  if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
731  if (!superclass_seen) {
732  c = p; /* move insertion point */
733  }
734  goto skip;
735  }
736  break;
737  case T_CLASS:
738  superclass_seen = TRUE;
739  break;
740  }
741  }
742  c = RCLASS_SUPER(c) = rb_include_class_new(module, RCLASS_SUPER(c));
743  if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
744  VALUE refined_class =
746 
748  (st_data_t) refined_class);
750  }
751  if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
752  changed = 1;
753  if (RMODULE_CONST_TBL(module) && RMODULE_CONST_TBL(module)->num_entries)
754  changed = 1;
755  skip:
756  module = RCLASS_SUPER(module);
757  }
758 
759  return changed;
760 }
761 
762 static int
764 {
765  rb_method_entry_t *me = (rb_method_entry_t *) value;
766  st_table *tbl = (st_table *) data;
767 
768  if (me->def->type == VM_METHOD_TYPE_REFINED) {
769  if (me->def->body.orig_me) {
770  rb_method_entry_t *orig_me = me->def->body.orig_me, *new_me;
771  me->def->body.orig_me = NULL;
772  new_me = ALLOC(rb_method_entry_t);
773  *new_me = *me;
774  st_add_direct(tbl, key, (st_data_t) new_me);
775  *me = *orig_me;
776  xfree(orig_me);
777  return ST_CONTINUE;
778  }
779  else {
780  st_add_direct(tbl, key, (st_data_t) me);
781  return ST_DELETE;
782  }
783  }
784  else {
785  return ST_CONTINUE;
786  }
787 }
788 
789 void
791 {
793  VALUE origin;
794  int changed = 0;
795 
796  rb_frozen_class_p(klass);
797  if (!OBJ_UNTRUSTED(klass)) {
798  rb_secure(4);
799  }
800 
801  Check_Type(module, T_MODULE);
802 
803  OBJ_INFECT(klass, module);
804 
805  origin = RCLASS_ORIGIN(klass);
806  if (origin == klass) {
807  origin = class_alloc(T_ICLASS, klass);
808  RCLASS_SUPER(origin) = RCLASS_SUPER(klass);
809  RCLASS_SUPER(klass) = origin;
810  RCLASS_ORIGIN(klass) = origin;
811  RCLASS_M_TBL(origin) = RCLASS_M_TBL(klass);
812  RCLASS_M_TBL(klass) = st_init_numtable();
814  (st_data_t) RCLASS_M_TBL(klass));
815  }
816  changed = include_modules_at(klass, klass, module);
817  if (changed < 0)
818  rb_raise(rb_eArgError, "cyclic prepend detected");
819  if (changed) {
820  rb_clear_cache();
822  }
823 }
824 
825 /*
826  * call-seq:
827  * mod.included_modules -> array
828  *
829  * Returns the list of modules included in <i>mod</i>.
830  *
831  * module Mixin
832  * end
833  *
834  * module Outer
835  * include Mixin
836  * end
837  *
838  * Mixin.included_modules #=> []
839  * Outer.included_modules #=> [Mixin]
840  */
841 
842 VALUE
844 {
845  VALUE ary = rb_ary_new();
846  VALUE p;
847  VALUE origin = RCLASS_ORIGIN(mod);
848 
849  for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
850  if (p != origin && BUILTIN_TYPE(p) == T_ICLASS) {
851  VALUE m = RBASIC(p)->klass;
852  if (RB_TYPE_P(m, T_MODULE))
853  rb_ary_push(ary, m);
854  }
855  }
856  return ary;
857 }
858 
859 /*
860  * call-seq:
861  * mod.include?(module) -> true or false
862  *
863  * Returns <code>true</code> if <i>module</i> is included in
864  * <i>mod</i> or one of <i>mod</i>'s ancestors.
865  *
866  * module A
867  * end
868  * class B
869  * include A
870  * end
871  * class C < B
872  * end
873  * B.include?(A) #=> true
874  * C.include?(A) #=> true
875  * A.include?(A) #=> false
876  */
877 
878 VALUE
880 {
881  VALUE p;
882 
883  Check_Type(mod2, T_MODULE);
884  for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
885  if (BUILTIN_TYPE(p) == T_ICLASS) {
886  if (RBASIC(p)->klass == mod2) return Qtrue;
887  }
888  }
889  return Qfalse;
890 }
891 
892 /*
893  * call-seq:
894  * mod.ancestors -> array
895  *
896  * Returns a list of modules included in <i>mod</i> (including
897  * <i>mod</i> itself).
898  *
899  * module Mod
900  * include Math
901  * include Comparable
902  * end
903  *
904  * Mod.ancestors #=> [Mod, Comparable, Math]
905  * Math.ancestors #=> [Math]
906  */
907 
908 VALUE
910 {
911  VALUE p, ary = rb_ary_new();
912 
913  for (p = mod; p; p = RCLASS_SUPER(p)) {
914  if (FL_TEST(p, FL_SINGLETON))
915  continue;
916  if (BUILTIN_TYPE(p) == T_ICLASS) {
917  rb_ary_push(ary, RBASIC(p)->klass);
918  }
919  else if (p == RCLASS_ORIGIN(p)) {
920  rb_ary_push(ary, p);
921  }
922  }
923  return ary;
924 }
925 
926 #define VISI(x) ((x)&NOEX_MASK)
927 #define VISI_CHECK(x,f) (VISI(x) == (f))
928 
929 static int
930 ins_methods_push(ID name, long type, VALUE ary, long visi)
931 {
932  if (type == -1) return ST_CONTINUE;
933 
934  switch (visi) {
935  case NOEX_PRIVATE:
936  case NOEX_PROTECTED:
937  case NOEX_PUBLIC:
938  visi = (type == visi);
939  break;
940  default:
941  visi = (type != NOEX_PRIVATE);
942  break;
943  }
944  if (visi) {
945  rb_ary_push(ary, ID2SYM(name));
946  }
947  return ST_CONTINUE;
948 }
949 
950 static int
952 {
953  return ins_methods_push((ID)name, (long)type, (VALUE)ary, -1); /* everything but private */
954 }
955 
956 static int
958 {
959  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PROTECTED);
960 }
961 
962 static int
964 {
965  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PRIVATE);
966 }
967 
968 static int
970 {
971  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PUBLIC);
972 }
973 
976  int recur;
977 };
978 
979 static int
981 {
982  const rb_method_entry_t *me = (const rb_method_entry_t *)value;
983  struct method_entry_arg *arg = (struct method_entry_arg *)data;
984  long type;
985 
986  if (me && me->def->type == VM_METHOD_TYPE_REFINED) {
987  VALUE klass = me->klass;
989  if (!me) return ST_CONTINUE;
990  if (!arg->recur && me->klass != klass) return ST_CONTINUE;
991  }
992  if (!st_lookup(arg->list, key, 0)) {
993  if (UNDEFINED_METHOD_ENTRY_P(me)) {
994  type = -1; /* none */
995  }
996  else {
997  type = VISI(me->flag);
998  }
999  st_add_direct(arg->list, key, type);
1000  }
1001  return ST_CONTINUE;
1002 }
1003 
1004 static VALUE
1006 {
1007  VALUE ary;
1008  int recur, prepended = 0;
1009  struct method_entry_arg me_arg;
1010 
1011  if (argc == 0) {
1012  recur = TRUE;
1013  }
1014  else {
1015  VALUE r;
1016  rb_scan_args(argc, argv, "01", &r);
1017  recur = RTEST(r);
1018  }
1019 
1020  if (!recur && RCLASS_ORIGIN(mod) != mod) {
1021  mod = RCLASS_ORIGIN(mod);
1022  prepended = 1;
1023  }
1024 
1025  me_arg.list = st_init_numtable();
1026  me_arg.recur = recur;
1027  for (; mod; mod = RCLASS_SUPER(mod)) {
1029  if (BUILTIN_TYPE(mod) == T_ICLASS && !prepended) continue;
1030  if (obj && FL_TEST(mod, FL_SINGLETON)) continue;
1031  if (!recur) break;
1032  }
1033  ary = rb_ary_new();
1034  st_foreach(me_arg.list, func, ary);
1035  st_free_table(me_arg.list);
1036 
1037  return ary;
1038 }
1039 
1040 /*
1041  * call-seq:
1042  * mod.instance_methods(include_super=true) -> array
1043  *
1044  * Returns an array containing the names of the public and protected instance
1045  * methods in the receiver. For a module, these are the public and protected methods;
1046  * for a class, they are the instance (not singleton) methods. With no
1047  * argument, or with an argument that is <code>false</code>, the
1048  * instance methods in <i>mod</i> are returned, otherwise the methods
1049  * in <i>mod</i> and <i>mod</i>'s superclasses are returned.
1050  *
1051  * module A
1052  * def method1() end
1053  * end
1054  * class B
1055  * def method2() end
1056  * end
1057  * class C < B
1058  * def method3() end
1059  * end
1060  *
1061  * A.instance_methods #=> [:method1]
1062  * B.instance_methods(false) #=> [:method2]
1063  * C.instance_methods(false) #=> [:method3]
1064  * C.instance_methods(true).length #=> 43
1065  */
1066 
1067 VALUE
1069 {
1071 }
1072 
1073 /*
1074  * call-seq:
1075  * mod.protected_instance_methods(include_super=true) -> array
1076  *
1077  * Returns a list of the protected instance methods defined in
1078  * <i>mod</i>. If the optional parameter is not <code>false</code>, the
1079  * methods of any ancestors are included.
1080  */
1081 
1082 VALUE
1084 {
1086 }
1087 
1088 /*
1089  * call-seq:
1090  * mod.private_instance_methods(include_super=true) -> array
1091  *
1092  * Returns a list of the private instance methods defined in
1093  * <i>mod</i>. If the optional parameter is not <code>false</code>, the
1094  * methods of any ancestors are included.
1095  *
1096  * module Mod
1097  * def method1() end
1098  * private :method1
1099  * def method2() end
1100  * end
1101  * Mod.instance_methods #=> [:method2]
1102  * Mod.private_instance_methods #=> [:method1]
1103  */
1104 
1105 VALUE
1107 {
1109 }
1110 
1111 /*
1112  * call-seq:
1113  * mod.public_instance_methods(include_super=true) -> array
1114  *
1115  * Returns a list of the public instance methods defined in <i>mod</i>.
1116  * If the optional parameter is not <code>false</code>, the methods of
1117  * any ancestors are included.
1118  */
1119 
1120 VALUE
1122 {
1124 }
1125 
1126 /*
1127  * call-seq:
1128  * obj.methods(all=true) -> array
1129  *
1130  * Returns a list of the names of public and protected methods of
1131  * <i>obj</i>. This will include all the methods accessible in
1132  * <i>obj</i>'s ancestors.
1133  * If the <i>all</i> parameter is set to <code>false</code>, only those methods
1134  * in the receiver will be listed.
1135  *
1136  * class Klass
1137  * def klass_method()
1138  * end
1139  * end
1140  * k = Klass.new
1141  * k.methods[0..9] #=> [:klass_method, :nil?, :===,
1142  * # :==~, :!, :eql?
1143  * # :hash, :<=>, :class, :singleton_class]
1144  * k.methods.length #=> 57
1145  */
1146 
1147 VALUE
1149 {
1150  retry:
1151  if (argc == 0) {
1153  }
1154  else {
1155  VALUE recur;
1156 
1157  rb_scan_args(argc, argv, "1", &recur);
1158  if (RTEST(recur)) {
1159  argc = 0;
1160  goto retry;
1161  }
1162  return rb_obj_singleton_methods(argc, argv, obj);
1163  }
1164 }
1165 
1166 /*
1167  * call-seq:
1168  * obj.protected_methods(all=true) -> array
1169  *
1170  * Returns the list of protected methods accessible to <i>obj</i>. If
1171  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1172  * in the receiver will be listed.
1173  */
1174 
1175 VALUE
1177 {
1179 }
1180 
1181 /*
1182  * call-seq:
1183  * obj.private_methods(all=true) -> array
1184  *
1185  * Returns the list of private methods accessible to <i>obj</i>. If
1186  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1187  * in the receiver will be listed.
1188  */
1189 
1190 VALUE
1192 {
1194 }
1195 
1196 /*
1197  * call-seq:
1198  * obj.public_methods(all=true) -> array
1199  *
1200  * Returns the list of public methods accessible to <i>obj</i>. If
1201  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1202  * in the receiver will be listed.
1203  */
1204 
1205 VALUE
1207 {
1209 }
1210 
1211 /*
1212  * call-seq:
1213  * obj.singleton_methods(all=true) -> array
1214  *
1215  * Returns an array of the names of singleton methods for <i>obj</i>.
1216  * If the optional <i>all</i> parameter is true, the list will include
1217  * methods in modules included in <i>obj</i>.
1218  * Only public and protected singleton methods are returned.
1219  *
1220  * module Other
1221  * def three() end
1222  * end
1223  *
1224  * class Single
1225  * def Single.four() end
1226  * end
1227  *
1228  * a = Single.new
1229  *
1230  * def a.one()
1231  * end
1232  *
1233  * class << a
1234  * include Other
1235  * def two()
1236  * end
1237  * end
1238  *
1239  * Single.singleton_methods #=> [:four]
1240  * a.singleton_methods(false) #=> [:two, :one]
1241  * a.singleton_methods #=> [:two, :one, :three]
1242  */
1243 
1244 VALUE
1246 {
1247  VALUE recur, ary, klass, origin;
1248  struct method_entry_arg me_arg;
1249  st_table *mtbl;
1250 
1251  if (argc == 0) {
1252  recur = Qtrue;
1253  }
1254  else {
1255  rb_scan_args(argc, argv, "01", &recur);
1256  }
1257  klass = CLASS_OF(obj);
1258  origin = RCLASS_ORIGIN(klass);
1259  me_arg.list = st_init_numtable();
1260  me_arg.recur = RTEST(recur);
1261  if (klass && FL_TEST(klass, FL_SINGLETON)) {
1262  if ((mtbl = RCLASS_M_TBL(origin)) != 0)
1263  st_foreach(mtbl, method_entry_i, (st_data_t)&me_arg);
1264  klass = RCLASS_SUPER(klass);
1265  }
1266  if (RTEST(recur)) {
1267  while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
1268  if (klass != origin && (mtbl = RCLASS_M_TBL(klass)) != 0)
1269  st_foreach(mtbl, method_entry_i, (st_data_t)&me_arg);
1270  klass = RCLASS_SUPER(klass);
1271  }
1272  }
1273  ary = rb_ary_new();
1274  st_foreach(me_arg.list, ins_methods_i, ary);
1275  st_free_table(me_arg.list);
1276 
1277  return ary;
1278 }
1279 
1337 void
1339 {
1340  rb_add_method_cfunc(klass, mid, func, argc, NOEX_PUBLIC);
1341 }
1342 
1343 void
1344 rb_define_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
1345 {
1347 }
1348 
1349 void
1351 {
1353 }
1354 
1355 void
1357 {
1359 }
1360 
1361 void
1362 rb_undef_method(VALUE klass, const char *name)
1363 {
1365 }
1366 
1375 #define SPECIAL_SINGLETON(x,c) do {\
1376  if (obj == (x)) {\
1377  return (c);\
1378  }\
1379 } while (0)
1380 
1381 static inline VALUE
1383 {
1387  return Qnil;
1388 }
1389 
1390 VALUE
1392 {
1393  return special_singleton_class_of(obj);
1394 }
1395 
1405 static VALUE
1407 {
1408  VALUE klass;
1409 
1410  if (FIXNUM_P(obj) || FLONUM_P(obj) || SYMBOL_P(obj)) {
1411  rb_raise(rb_eTypeError, "can't define singleton");
1412  }
1413  if (SPECIAL_CONST_P(obj)) {
1414  klass = special_singleton_class_of(obj);
1415  if (NIL_P(klass))
1416  rb_bug("unknown immediate %p", (void *)obj);
1417  return klass;
1418  }
1419  else {
1420  enum ruby_value_type type = BUILTIN_TYPE(obj);
1421  if (type == T_FLOAT || type == T_BIGNUM) {
1422  rb_raise(rb_eTypeError, "can't define singleton");
1423  }
1424  }
1425 
1426  if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) &&
1427  rb_ivar_get(RBASIC(obj)->klass, id_attached) == obj) {
1428  klass = RBASIC(obj)->klass;
1429  }
1430  else {
1431  klass = rb_make_metaclass(obj, RBASIC(obj)->klass);
1432  }
1433 
1434  if (OBJ_TAINTED(obj)) {
1435  OBJ_TAINT(klass);
1436  }
1437  else {
1438  FL_UNSET(klass, FL_TAINT);
1439  }
1440  if (OBJ_UNTRUSTED(obj)) {
1441  OBJ_UNTRUST(klass);
1442  }
1443  else {
1444  FL_UNSET(klass, FL_UNTRUSTED);
1445  }
1446  if (OBJ_FROZEN(obj)) OBJ_FREEZE(klass);
1447 
1448  return klass;
1449 }
1450 
1451 
1469 VALUE
1471 {
1472  VALUE klass = singleton_class_of(obj);
1473 
1474  /* ensures an exposed class belongs to its own eigenclass */
1475  if (RB_TYPE_P(obj, T_CLASS)) (void)ENSURE_EIGENCLASS(klass);
1476 
1477  return klass;
1478 }
1479 
1496 void
1498 {
1500 }
1501 
1502 
1503 
1511 void
1513 {
1516 }
1517 
1518 
1525 void
1527 {
1529 }
1530 
1531 
1538 void
1539 rb_define_alias(VALUE klass, const char *name1, const char *name2)
1540 {
1541  rb_alias(klass, rb_intern(name1), rb_intern(name2));
1542 }
1543 
1551 void
1552 rb_define_attr(VALUE klass, const char *name, int read, int write)
1553 {
1554  rb_attr(klass, rb_intern(name), read, write, FALSE);
1555 }
1556 
1557 int
1559 {
1560  const rb_method_entry_t *me = rb_method_entry(CLASS_OF(obj), rb_intern("to_s"), 0);
1561  if (me && me->def && me->def->type == VM_METHOD_TYPE_CFUNC &&
1562  me->def->body.cfunc.func == rb_any_to_s)
1563  return 1;
1564  return 0;
1565 }
1566 
1567 #include <stdarg.h>
1568 
1569 int
1570 rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
1571 {
1572  int i;
1573  const char *p = fmt;
1574  VALUE *var;
1575  va_list vargs;
1576  int f_var = 0, f_hash = 0, f_block = 0;
1577  int n_lead = 0, n_opt = 0, n_trail = 0, n_mand;
1578  int argi = 0;
1579  VALUE hash = Qnil;
1580 
1581  if (ISDIGIT(*p)) {
1582  n_lead = *p - '0';
1583  p++;
1584  if (ISDIGIT(*p)) {
1585  n_opt = *p - '0';
1586  p++;
1587  if (ISDIGIT(*p)) {
1588  n_trail = *p - '0';
1589  p++;
1590  goto block_arg;
1591  }
1592  }
1593  }
1594  if (*p == '*') {
1595  f_var = 1;
1596  p++;
1597  if (ISDIGIT(*p)) {
1598  n_trail = *p - '0';
1599  p++;
1600  }
1601  }
1602  block_arg:
1603  if (*p == ':') {
1604  f_hash = 1;
1605  p++;
1606  }
1607  if (*p == '&') {
1608  f_block = 1;
1609  p++;
1610  }
1611  if (*p != '\0') {
1612  rb_fatal("bad scan arg format: %s", fmt);
1613  }
1614  n_mand = n_lead + n_trail;
1615 
1616  if (argc < n_mand)
1617  goto argc_error;
1618 
1619  va_start(vargs, fmt);
1620 
1621  /* capture an option hash - phase 1: pop */
1622  if (f_hash && n_mand < argc) {
1623  VALUE last = argv[argc - 1];
1624 
1625  if (NIL_P(last)) {
1626  /* nil is taken as an empty option hash only if it is not
1627  ambiguous; i.e. '*' is not specified and arguments are
1628  given more than sufficient */
1629  if (!f_var && n_mand + n_opt < argc)
1630  argc--;
1631  }
1632  else {
1634  if (!NIL_P(hash))
1635  argc--;
1636  }
1637  }
1638  /* capture leading mandatory arguments */
1639  for (i = n_lead; i-- > 0; ) {
1640  var = va_arg(vargs, VALUE *);
1641  if (var) *var = argv[argi];
1642  argi++;
1643  }
1644  /* capture optional arguments */
1645  for (i = n_opt; i-- > 0; ) {
1646  var = va_arg(vargs, VALUE *);
1647  if (argi < argc - n_trail) {
1648  if (var) *var = argv[argi];
1649  argi++;
1650  }
1651  else {
1652  if (var) *var = Qnil;
1653  }
1654  }
1655  /* capture variable length arguments */
1656  if (f_var) {
1657  int n_var = argc - argi - n_trail;
1658 
1659  var = va_arg(vargs, VALUE *);
1660  if (0 < n_var) {
1661  if (var) *var = rb_ary_new4(n_var, &argv[argi]);
1662  argi += n_var;
1663  }
1664  else {
1665  if (var) *var = rb_ary_new();
1666  }
1667  }
1668  /* capture trailing mandatory arguments */
1669  for (i = n_trail; i-- > 0; ) {
1670  var = va_arg(vargs, VALUE *);
1671  if (var) *var = argv[argi];
1672  argi++;
1673  }
1674  /* capture an option hash - phase 2: assignment */
1675  if (f_hash) {
1676  var = va_arg(vargs, VALUE *);
1677  if (var) *var = hash;
1678  }
1679  /* capture iterator block */
1680  if (f_block) {
1681  var = va_arg(vargs, VALUE *);
1682  if (rb_block_given_p()) {
1683  *var = rb_block_proc();
1684  }
1685  else {
1686  *var = Qnil;
1687  }
1688  }
1689  va_end(vargs);
1690 
1691  if (argi < argc) {
1692  argc_error:
1693  rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt);
1694  }
1695 
1696  return argc;
1697 }
1698 
static VALUE make_metaclass(VALUE klass)
Creates a metaclass of klass.
Definition: class.c:329
st_table * list
Definition: class.c:975
#define UNDEFINED_METHOD_ENTRY_P(me)
Definition: method.h:108
Definition: st.h:108
VALUE rb_define_module_id_under(VALUE outer, ID id)
Definition: class.c:632
void rb_vm_check_redefinition_by_prepend(VALUE klass)
Definition: vm.c:1084
VALUE rb_ary_new4(long n, const VALUE *elts)
Definition: array.c:451
RUBY_EXTERN VALUE rb_cFalseClass
Definition: ruby.h:1434
VALUE rb_mod_include_p(VALUE mod, VALUE mod2)
Definition: class.c:879
void rb_bug(const char *fmt,...)
Definition: error.c:295
rb_method_type_t type
Definition: method.h:77
#define FALSE
Definition: nkf.h:174
void rb_check_inheritable(VALUE super)
Ensures a class can be derived from super.
Definition: class.c:95
static int ins_methods_push(ID name, long type, VALUE ary, long visi)
Definition: class.c:930
int i
Definition: win32ole.c:784
static ID id_attached
Definition: class.c:35
#define RCLASS_CONST_TBL(c)
Definition: internal.h:48
Definition: constant.h:19
Definition: st.h:77
VALUE rb_obj_private_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1191
VALUE rb_id2str(ID id)
Definition: ripper.c:16946
#define VISI(x)
Definition: class.c:926
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1497
rb_method_flag_t flag
Definition: method.h:96
VALUE rb_class_private_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1106
#define FL_TAINT
Definition: ruby.h:1115
#define CLASS_OF(v)
Definition: ruby.h:448
#define T_MODULE
Definition: ruby.h:488
VALUE rb_define_class_id_under(VALUE outer, ID id, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:557
#define RCLASS_EXT(c)
Definition: classext.h:15
#define Qtrue
Definition: ruby.h:434
int st_insert(st_table *, st_data_t, st_data_t)
static VALUE class_alloc(VALUE flags, VALUE klass)
Allocates a struct RClass for a new class.
Definition: class.c:50
#define OBJ_INIT_COPY(obj, orig)
Definition: intern.h:268
struct rb_method_entry_struct * orig_me
Definition: method.h:90
VALUE rb_mod_ancestors(VALUE mod)
Definition: class.c:909
const int id
Definition: nkf.c:209
VALUE rb_refinement_module_get_refined_class(VALUE module)
Definition: eval.c:1135
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1356
VALUE rb_eTypeError
Definition: error.c:516
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:822
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:108
VALUE rb_singleton_class_clone(VALUE obj)
Definition: class.c:230
void st_free_table(st_table *)
Definition: st.c:334
VALUE rb_mod_init_copy(VALUE clone, VALUE orig)
Definition: class.c:181
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:773
union rb_method_definition_struct::@90 body
void Init_class_hierarchy(void)
Definition: class.c:390
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:534
#define Check_Type(v, t)
Definition: ruby.h:539
static int ins_methods_priv_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:963
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1788
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1116
Definition: class.c:974
static int clone_const_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:160
#define RB_GC_GUARD(v)
Definition: ruby.h:530
int rb_const_defined(VALUE, ID)
Definition: variable.c:2103
void rb_include_module(VALUE klass, VALUE module)
Definition: class.c:684
void rb_define_protected_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1350
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1526
#define ISDIGIT(c)
unsigned int last
Definition: nkf.c:4310
#define RMODULE_M_TBL(m)
Definition: ruby.h:746
#define FIXNUM_P(f)
Definition: ruby.h:355
void rb_undef_method(VALUE klass, const char *name)
Definition: class.c:1362
#define OBJ_TAINTED(x)
Definition: ruby.h:1153
const char * rb_obj_classname(VALUE)
Definition: variable.c:396
void rb_name_error(ID id, const char *fmt,...)
Definition: error.c:904
Definition: node.h:239
#define NEWOBJ_OF(obj, type, klass, flags)
Definition: ruby.h:683
Win32OLEIDispatch * p
Definition: win32ole.c:786
#define FL_SINGLETON
Definition: ruby.h:1111
void rb_prepend_module(VALUE klass, VALUE module)
Definition: class.c:790
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1470
#define RB_TYPE_P(obj, type)
Definition: ruby.h:1537
#define FL_UNTRUSTED
Definition: ruby.h:1116
int st_lookup(st_table *, st_data_t, st_data_t *)
rb_method_cfunc_t cfunc
Definition: method.h:81
#define FL_TEST(x, f)
Definition: ruby.h:1146
VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
Definition: class.c:462
NODE * cref_stack
Definition: vm_core.h:304
int rb_block_given_p(void)
Definition: eval.c:672
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1426
VALUE rb_special_singleton_class(VALUE obj)
Definition: class.c:1391
#define RMODULE_IS_REFINEMENT
Definition: ruby.h:749
void rb_attr(VALUE, ID, int, int, int)
Definition: vm_method.c:824
static VALUE boot_defclass(const char *name, VALUE super)
Definition: class.c:377
VALUE rb_class_real(VALUE)
Definition: object.c:171
RUBY_EXTERN VALUE rb_cBasicObject
Definition: ruby.h:1425
VALUE rb_ary_new(void)
Definition: array.c:424
static void clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
Definition: class.c:125
#define RMODULE_CONST_TBL(m)
Definition: ruby.h:745
RUBY_EXTERN VALUE rb_mKernel
Definition: ruby.h:1414
#define RCLASS_ORIGIN(c)
Definition: internal.h:51
#define NIL_P(v)
Definition: ruby.h:446
void st_add_direct(st_table *, st_data_t, st_data_t)
Definition: st.c:629
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:488
RUBY_EXTERN VALUE rb_cTrueClass
Definition: ruby.h:1461
static VALUE special_singleton_class_of(VALUE obj)
Definition: class.c:1382
int st_delete(st_table *, st_data_t *, st_data_t *)
#define RCLASS_IV_TBL(c)
Definition: internal.h:47
VALUE rb_define_module_id(ID id)
Definition: class.c:595
#define METACLASS_OF(k)
Definition: class.c:290
#define OBJ_FROZEN(x)
Definition: ruby.h:1163
#define FLONUM_P(x)
Definition: ruby.h:375
#define META_CLASS_OF_CLASS_CLASS_P(k)
whether k is a meta^(n)-class of Class class
Definition: class.c:297
#define T_FLOAT
Definition: ruby.h:489
#define OBJ_UNTRUST(x)
Definition: ruby.h:1156
int argc
Definition: ruby.c:130
#define Qfalse
Definition: ruby.h:433
Definition: method.h:95
RUBY_EXTERN VALUE rb_cModule
Definition: ruby.h:1445
#define T_BIGNUM
Definition: ruby.h:495
void rb_gc_register_mark_object(VALUE obj)
Definition: gc.c:2982
VALUE rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1176
#define OBJ_FREEZE(x)
Definition: ruby.h:1164
rb_method_entry_t * rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me, VALUE *defined_class_ptr)
Definition: vm_method.c:607
rb_method_entry_t * rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr)
Definition: vm_method.c:572
VALUE klass
Definition: method.h:100
#define ALLOC(type)
Definition: ruby.h:1224
int rb_obj_basic_to_s_p(VALUE obj)
Definition: class.c:1558
#define RCLASS_REFINED_CLASS(c)
Definition: internal.h:52
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:1876
VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase)
Definition: iseq.c:1900
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
Definition: class.c:1539
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
Definition: class.c:1512
#define RCLASS_M_TBL(c)
Definition: internal.h:49
static int add_refined_method_entry_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:706
static VALUE class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int(*func)(st_data_t, st_data_t, st_data_t))
Definition: class.c:1005
#define TRUE
Definition: nkf.h:175
#define OBJ_UNTRUSTED(x)
Definition: ruby.h:1155
VALUE rb_include_class_new(VALUE module, VALUE super)
Definition: class.c:652
void rb_fatal(const char *fmt,...)
Definition: error.c:1842
int recur
Definition: class.c:976
rb_method_entry_t * rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex)
Definition: vm_method.c:405
VALUE(* func)(ANYARGS)
Definition: method.h:64
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1570
VALUE rb_check_hash_type(VALUE hash)
Definition: hash.c:461
unsigned long ID
Definition: ruby.h:105
static int ins_methods_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:951
#define Qnil
Definition: ruby.h:435
void rb_clear_cache(void)
Definition: vm_method.c:46
void rb_const_set(VALUE, ID, VALUE)
Definition: variable.c:2141
int type
Definition: tcltklib.c:111
static int include_modules_at(const VALUE klass, VALUE c, VALUE module)
Definition: class.c:713
VALUE rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1206
static int ins_methods_pub_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:969
#define BUILTIN_TYPE(x)
Definition: ruby.h:510
#define OBJ_TAINT(x)
Definition: ruby.h:1154
unsigned long VALUE
Definition: ruby.h:104
void rb_name_class(VALUE, ID)
Definition: variable.c:377
#define RBASIC(obj)
Definition: ruby.h:1094
const char * rb_class2name(VALUE)
Definition: variable.c:389
VALUE rb_make_metaclass(VALUE obj, VALUE unused)
Definition: class.c:419
void rb_alias(VALUE, ID, ID)
Definition: vm_method.c:1209
RUBY_EXTERN VALUE rb_cClass
Definition: ruby.h:1430
st_table * st_init_numtable(void)
Definition: st.c:272
ruby_value_type
Definition: ruby.h:450
VALUE rb_class_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1068
void xfree(void *)
#define FL_UNSET(x, f)
Definition: ruby.h:1150
void rb_free_const_table(st_table *tbl)
Definition: gc.c:814
VALUE rb_define_module_under(VALUE outer, const char *name)
Definition: class.c:626
#define recur(fmt)
VALUE rb_class_protected_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1083
int rb_const_defined_at(VALUE, ID)
Definition: variable.c:2109
void rb_define_method_id(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1338
VALUE rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1121
void rb_singleton_class_attached(VALUE klass, VALUE obj)
Attach a object to a singleton class.
Definition: class.c:278
#define UNLIMITED_ARGUMENTS
Definition: intern.h:54
#define RCLASS_SUPER(c)
Definition: classext.h:16
VALUE rb_module_new(void)
Definition: class.c:585
#define ENSURE_EIGENCLASS(klass)
ensures klass belongs to its own eigenclass.
Definition: class.c:315
VALUE rb_block_proc(void)
Definition: proc.c:458
VALUE rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1245
rb_method_definition_t * def
Definition: method.h:98
void rb_define_attr(VALUE klass, const char *name, int read, int write)
Defines (a) public accessor method(s) for an attribute.
Definition: class.c:1552
#define ANYARGS
Definition: defines.h:57
void rb_error_arity(int argc, int min, int max)
#define RCLASS_IV_INDEX_TBL(c)
Definition: internal.h:50
uint8_t key[16]
Definition: random.c:1370
static VALUE make_singleton_class(VALUE obj)
Creates a singleton class for obj.
Definition: class.c:362
VALUE rb_any_to_s(VALUE)
Definition: object.c:393
#define RTEST(v)
Definition: ruby.h:445
static int method_entry_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:980
#define OBJ_INFECT(x, s)
Definition: ruby.h:1157
VALUE rb_obj_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1148
void rb_add_refined_method_entry(VALUE refined_class, ID mid)
Definition: vm_method.c:212
static int ins_methods_prot_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:957
static unsigned int hash(const char *str, unsigned int len)
Definition: lex.c:56
#define T_CLASS
Definition: ruby.h:486
static int move_refined_method(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:763
VALUE rb_const_get_at(VALUE, ID)
Definition: variable.c:1882
void rb_frozen_class_p(VALUE klass)
Definition: eval.c:403
const char * name
Definition: nkf.c:208
static void class_init_copy_check(VALUE clone, VALUE orig)
Definition: class.c:166
#define FL_SET(x, f)
Definition: ruby.h:1149
VALUE self
Definition: vm_core.h:292
#define ID2SYM(x)
Definition: ruby.h:363
#define GetISeqPtr(obj, ptr)
Definition: vm_core.h:183
#define RMODULE_INCLUDED_INTO_REFINEMENT
Definition: ruby.h:750
const char * rb_id2name(ID id)
Definition: ripper.c:17012
unsigned long st_data_t
Definition: st.h:35
VALUE rb_mod_included_modules(VALUE mod)
Definition: class.c:843
st_table * rb_class_tbl
Definition: variable.c:23
VALUE rb_define_class_id(ID id, VALUE super)
Defines a new class.
Definition: class.c:441
st_table * st_copy(st_table *)
Definition: st.c:663
void rb_secure(int)
Definition: safe.c:79
#define SPECIAL_SINGLETON(x, c)
Definition: class.c:1375
rb_method_entry_t * rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex)
Definition: vm_method.c:478
#define CONST_ID(var, str)
Definition: ruby.h:1318
#define SPECIAL_CONST_P(x)
Definition: ruby.h:1143
VALUE rb_define_module(const char *name)
Definition: class.c:606
#define rb_intern(str)
static int clone_const(ID key, const rb_const_entry_t *ce, st_table *tbl)
Definition: class.c:151
#define SYMBOL_P(x)
Definition: ruby.h:362
#define mod(x, y)
Definition: date_strftime.c:28
#define NULL
Definition: _sdbm.c:102
static VALUE singleton_class_of(VALUE obj)
Definition: class.c:1406
Definition: ruby.h:737
static int clone_method_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:144
#define Qundef
Definition: ruby.h:436
#define T_ICLASS
Definition: ruby.h:487
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc, rb_method_flag_t noex)
Definition: vm_method.c:84
VALUE rb_class_new(VALUE super)
Creates a new class.
Definition: class.c:117
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1344
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
Definition: st.c:1006
void rb_warn(const char *fmt,...)
Definition: error.c:221
VALUE rb_class_boot(VALUE super)
A utility function that wraps class_alloc.
Definition: class.c:76
RUBY_EXTERN VALUE rb_cNilClass
Definition: ruby.h:1447
VALUE rb_eArgError
Definition: error.c:517
void rb_free_m_table(st_table *tbl)
Definition: gc.c:800
void rb_set_class_path_string(VALUE, VALUE, VALUE)
Definition: variable.c:285
void rb_vm_rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr)
char ** argv
Definition: ruby.c:131
VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
Definition: class.c:236