Ruby  2.0.0p598(2014-11-13revision48408)
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
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;
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 NODE*
125 rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass)
126 {
127  NODE *new_node;
128  if (!node) {
129  return NULL;
130  }
131  if (node->nd_clss == old_klass) {
132  new_node = NEW_CREF(new_klass);
133  new_node->nd_next = node->nd_next;
134  } else {
135  new_node = NEW_CREF(node->nd_clss);
136  new_node->nd_next = rewrite_cref_stack(node->nd_next, old_klass, new_klass);
137  }
138  return new_node;
139 }
140 
141 static void
143 {
144  VALUE newiseqval;
145  if (me->def && me->def->type == VM_METHOD_TYPE_ISEQ) {
146  rb_iseq_t *iseq;
147  newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass);
148  GetISeqPtr(newiseqval, iseq);
149  iseq->cref_stack = rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass);
150  rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
151  RB_GC_GUARD(newiseqval);
152  }
153  else {
154  rb_method_entry_set(klass, mid, me, me->flag);
155  }
156 }
157 
158 static int
160 {
161  clone_method((VALUE)data, (ID)key, (const rb_method_entry_t *)value);
162  return ST_CONTINUE;
163 }
164 
165 static int
167 {
169  *nce = *ce;
170  st_insert(tbl, key, (st_data_t)nce);
171  return ST_CONTINUE;
172 }
173 
174 static int
176 {
177  return clone_const((ID)key, (const rb_const_entry_t *)value, (st_table *)data);
178 }
179 
180 static void
182 {
183  if (orig == rb_cBasicObject) {
184  rb_raise(rb_eTypeError, "can't copy the root class");
185  }
186  if (RCLASS_SUPER(clone) != 0 || clone == rb_cBasicObject) {
187  rb_raise(rb_eTypeError, "already initialized class");
188  }
189  if (FL_TEST(orig, FL_SINGLETON)) {
190  rb_raise(rb_eTypeError, "can't copy singleton class");
191  }
192 }
193 
194 /* :nodoc: */
195 VALUE
197 {
198  if (RB_TYPE_P(clone, T_CLASS)) {
199  class_init_copy_check(clone, orig);
200  }
201  if (!OBJ_INIT_COPY(clone, orig)) return clone;
202  if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
203  RBASIC(clone)->klass = rb_singleton_class_clone(orig);
205  }
206  RCLASS_SUPER(clone) = RCLASS_SUPER(orig);
207  RCLASS_EXT(clone)->allocator = RCLASS_EXT(orig)->allocator;
208  if (RCLASS_IV_TBL(clone)) {
210  RCLASS_IV_TBL(clone) = 0;
211  }
212  if (RCLASS_CONST_TBL(clone)) {
214  RCLASS_CONST_TBL(clone) = 0;
215  }
216  if (RCLASS_M_TBL(clone)) {
218  RCLASS_M_TBL(clone) = 0;
219  }
220  if (RCLASS_IV_TBL(orig)) {
221  st_data_t id;
222 
223  RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(orig));
224  CONST_ID(id, "__tmp_classpath__");
225  st_delete(RCLASS_IV_TBL(clone), &id, 0);
226  CONST_ID(id, "__classpath__");
227  st_delete(RCLASS_IV_TBL(clone), &id, 0);
228  CONST_ID(id, "__classid__");
229  st_delete(RCLASS_IV_TBL(clone), &id, 0);
230  }
231  if (RCLASS_CONST_TBL(orig)) {
232 
235  }
236  if (RCLASS_M_TBL(orig)) {
237  RCLASS_M_TBL(clone) = st_init_numtable();
239  }
240 
241  return clone;
242 }
243 
244 VALUE
246 {
248 }
249 
250 VALUE
252 {
253  VALUE klass = RBASIC(obj)->klass;
254 
255  if (!FL_TEST(klass, FL_SINGLETON))
256  return klass;
257  else {
258  /* copy singleton(unnamed) class */
259  VALUE clone = class_alloc(RBASIC(klass)->flags, 0);
260 
261  if (BUILTIN_TYPE(obj) == T_CLASS) {
262  RBASIC(clone)->klass = clone;
263  }
264  else {
265  RBASIC(clone)->klass = rb_singleton_class_clone(klass);
266  }
267 
268  RCLASS_SUPER(clone) = RCLASS_SUPER(klass);
269  RCLASS_EXT(clone)->allocator = RCLASS_EXT(klass)->allocator;
270  if (RCLASS_IV_TBL(klass)) {
271  RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(klass));
272  }
273  if (RCLASS_CONST_TBL(klass)) {
276  }
277  if (attach != Qundef) {
278  rb_singleton_class_attached(clone, attach);
279  }
280  RCLASS_M_TBL(clone) = st_init_numtable();
282  rb_singleton_class_attached(RBASIC(clone)->klass, clone);
283  FL_SET(clone, FL_SINGLETON);
284  return clone;
285  }
286 }
287 
292 void
294 {
295  if (FL_TEST(klass, FL_SINGLETON)) {
296  if (!RCLASS_IV_TBL(klass)) {
297  RCLASS_IV_TBL(klass) = st_init_numtable();
298  }
299  st_insert(RCLASS_IV_TBL(klass), id_attached, obj);
300  }
301 }
302 
303 
304 
305 #define METACLASS_OF(k) RBASIC(k)->klass
306 
312 #define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k))
313 
319 #define HAVE_METACLASS_P(k) \
320  (FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \
321  rb_ivar_get(METACLASS_OF(k), id_attached) == (k))
322 
330 #define ENSURE_EIGENCLASS(klass) \
331  (HAVE_METACLASS_P(klass) ? METACLASS_OF(klass) : make_metaclass(klass))
332 
333 
343 static inline VALUE
345 {
346  VALUE super;
347  VALUE metaclass = rb_class_boot(Qundef);
348 
349  FL_SET(metaclass, FL_SINGLETON);
350  rb_singleton_class_attached(metaclass, klass);
351 
352  if (META_CLASS_OF_CLASS_CLASS_P(klass)) {
353  METACLASS_OF(klass) = METACLASS_OF(metaclass) = metaclass;
354  }
355  else {
356  VALUE tmp = METACLASS_OF(klass); /* for a meta^(n)-class klass, tmp is meta^(n)-class of Class class */
357  METACLASS_OF(klass) = metaclass;
358  METACLASS_OF(metaclass) = ENSURE_EIGENCLASS(tmp);
359  }
360 
361  super = RCLASS_SUPER(klass);
362  while (RB_TYPE_P(super, T_ICLASS)) super = RCLASS_SUPER(super);
363  RCLASS_SUPER(metaclass) = super ? ENSURE_EIGENCLASS(super) : rb_cClass;
364 
365  OBJ_INFECT(metaclass, RCLASS_SUPER(metaclass));
366 
367  return metaclass;
368 }
369 
376 static inline VALUE
378 {
379  VALUE orig_class = RBASIC(obj)->klass;
380  VALUE klass = rb_class_boot(orig_class);
381 
382  FL_SET(klass, FL_SINGLETON);
383  RBASIC(obj)->klass = klass;
384  rb_singleton_class_attached(klass, obj);
385 
386  METACLASS_OF(klass) = METACLASS_OF(rb_class_real(orig_class));
387  return klass;
388 }
389 
390 
391 static VALUE
392 boot_defclass(const char *name, VALUE super)
393 {
394  extern st_table *rb_class_tbl;
395  VALUE obj = rb_class_boot(super);
396  ID id = rb_intern(name);
397 
398  rb_name_class(obj, id);
399  st_add_direct(rb_class_tbl, id, obj);
400  rb_const_set((rb_cObject ? rb_cObject : obj), id, obj);
401  return obj;
402 }
403 
404 void
406 {
407  id_attached = rb_intern("__attached__");
408 
409  rb_cBasicObject = boot_defclass("BasicObject", 0);
411  rb_cModule = boot_defclass("Module", rb_cObject);
412  rb_cClass = boot_defclass("Class", rb_cModule);
413 
415  RBASIC(rb_cClass)->klass
416  = RBASIC(rb_cModule)->klass
417  = RBASIC(rb_cObject)->klass
418  = RBASIC(rb_cBasicObject)->klass
419  = rb_cClass;
420 }
421 
422 
433 VALUE
435 {
436  if (BUILTIN_TYPE(obj) == T_CLASS) {
437  return make_metaclass(obj);
438  }
439  else {
440  return make_singleton_class(obj);
441  }
442 }
443 
444 
455 VALUE
457 {
458  VALUE klass;
459 
460  if (!super) super = rb_cObject;
461  klass = rb_class_new(super);
462  rb_make_metaclass(klass, RBASIC(super)->klass);
463 
464  return klass;
465 }
466 
467 
476 VALUE
478 {
479  ID inherited;
480  if (!super) super = rb_cObject;
481  CONST_ID(inherited, "inherited");
482  return rb_funcall(super, inherited, 1, klass);
483 }
484 
485 
486 
502 VALUE
503 rb_define_class(const char *name, VALUE super)
504 {
505  VALUE klass;
506  ID id;
507 
508  id = rb_intern(name);
509  if (rb_const_defined(rb_cObject, id)) {
510  klass = rb_const_get(rb_cObject, id);
511  if (!RB_TYPE_P(klass, T_CLASS)) {
512  rb_raise(rb_eTypeError, "%s is not a class", name);
513  }
514  if (rb_class_real(RCLASS_SUPER(klass)) != super) {
515  rb_raise(rb_eTypeError, "superclass mismatch for class %s", name);
516  }
517  return klass;
518  }
519  if (!super) {
520  rb_warn("no super class for `%s', Object assumed", name);
521  }
522  klass = rb_define_class_id(id, super);
523  st_add_direct(rb_class_tbl, id, klass);
524  rb_name_class(klass, id);
525  rb_const_set(rb_cObject, id, klass);
526  rb_class_inherited(super, klass);
527 
528  return klass;
529 }
530 
531 
548 VALUE
549 rb_define_class_under(VALUE outer, const char *name, VALUE super)
550 {
551  return rb_define_class_id_under(outer, rb_intern(name), super);
552 }
553 
554 
571 VALUE
573 {
574  VALUE klass;
575 
576  if (rb_const_defined_at(outer, id)) {
577  klass = rb_const_get_at(outer, id);
578  if (!RB_TYPE_P(klass, T_CLASS)) {
579  rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
580  }
581  if (rb_class_real(RCLASS_SUPER(klass)) != super) {
582  rb_name_error(id, "%s is already defined", rb_id2name(id));
583  }
584  return klass;
585  }
586  if (!super) {
587  rb_warn("no super class for `%s::%s', Object assumed",
588  rb_class2name(outer), rb_id2name(id));
589  }
590  klass = rb_define_class_id(id, super);
591  rb_set_class_path_string(klass, outer, rb_id2str(id));
592  rb_const_set(outer, id, klass);
593  rb_class_inherited(super, klass);
595 
596  return klass;
597 }
598 
599 VALUE
601 {
603 
605 
606  return (VALUE)mdl;
607 }
608 
609 VALUE
611 {
612  VALUE mdl;
613 
614  mdl = rb_module_new();
615  rb_name_class(mdl, id);
616 
617  return mdl;
618 }
619 
620 VALUE
621 rb_define_module(const char *name)
622 {
623  VALUE module;
624  ID id;
625 
626  id = rb_intern(name);
627  if (rb_const_defined(rb_cObject, id)) {
628  module = rb_const_get(rb_cObject, id);
629  if (RB_TYPE_P(module, T_MODULE))
630  return module;
631  rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module));
632  }
633  module = rb_define_module_id(id);
634  st_add_direct(rb_class_tbl, id, module);
635  rb_const_set(rb_cObject, id, module);
636 
637  return module;
638 }
639 
640 VALUE
641 rb_define_module_under(VALUE outer, const char *name)
642 {
643  return rb_define_module_id_under(outer, rb_intern(name));
644 }
645 
646 VALUE
648 {
649  VALUE module;
650 
651  if (rb_const_defined_at(outer, id)) {
652  module = rb_const_get_at(outer, id);
653  if (RB_TYPE_P(module, T_MODULE))
654  return module;
655  rb_raise(rb_eTypeError, "%s::%s is not a module",
656  rb_class2name(outer), rb_obj_classname(module));
657  }
658  module = rb_define_module_id(id);
659  rb_const_set(outer, id, module);
660  rb_set_class_path_string(module, outer, rb_id2str(id));
662 
663  return module;
664 }
665 
666 VALUE
668 {
670 
671  if (BUILTIN_TYPE(module) == T_ICLASS) {
672  module = RBASIC(module)->klass;
673  }
674  if (!RCLASS_IV_TBL(module)) {
675  RCLASS_IV_TBL(module) = st_init_numtable();
676  }
677  if (!RCLASS_CONST_TBL(module)) {
679  }
680  RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
681  RCLASS_CONST_TBL(klass) = RCLASS_CONST_TBL(module);
682  RCLASS_M_TBL(klass) = RCLASS_M_TBL(RCLASS_ORIGIN(module));
683  RCLASS_SUPER(klass) = super;
684  if (RB_TYPE_P(module, T_ICLASS)) {
685  RBASIC(klass)->klass = RBASIC(module)->klass;
686  }
687  else {
688  RBASIC(klass)->klass = module;
689  }
690  OBJ_INFECT(klass, module);
691  OBJ_INFECT(klass, super);
692 
693  return (VALUE)klass;
694 }
695 
696 static int include_modules_at(const VALUE klass, VALUE c, VALUE module);
697 
698 void
700 {
701  int changed = 0;
702 
703  rb_frozen_class_p(klass);
704  if (!OBJ_UNTRUSTED(klass)) {
705  rb_secure(4);
706  }
707 
708  if (!RB_TYPE_P(module, T_MODULE)) {
709  Check_Type(module, T_MODULE);
710  }
711 
712  OBJ_INFECT(klass, module);
713 
714  changed = include_modules_at(klass, RCLASS_ORIGIN(klass), module);
715  if (changed < 0)
716  rb_raise(rb_eArgError, "cyclic include detected");
717  if (changed) rb_clear_cache();
718 }
719 
720 static int
722 {
723  rb_add_refined_method_entry((VALUE) data, (ID) key);
724  return ST_CONTINUE;
725 }
726 
727 static int
729 {
730  VALUE p;
731  int changed = 0;
732  const st_table *const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass));
733 
734  while (module) {
735  int superclass_seen = FALSE;
736 
737  if (RCLASS_ORIGIN(module) != module)
738  goto skip;
739  if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module))
740  return -1;
741  /* ignore if the module included already in superclasses */
742  for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
743  switch (BUILTIN_TYPE(p)) {
744  case T_ICLASS:
745  if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
746  if (!superclass_seen) {
747  c = p; /* move insertion point */
748  }
749  goto skip;
750  }
751  break;
752  case T_CLASS:
753  superclass_seen = TRUE;
754  break;
755  }
756  }
757  c = RCLASS_SUPER(c) = rb_include_class_new(module, RCLASS_SUPER(c));
758  if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
759  VALUE refined_class =
761 
763  (st_data_t) refined_class);
765  }
766  if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
767  changed = 1;
768  if (RMODULE_CONST_TBL(module) && RMODULE_CONST_TBL(module)->num_entries)
769  changed = 1;
770  skip:
771  module = RCLASS_SUPER(module);
772  }
773 
774  return changed;
775 }
776 
777 static int
779 {
780  rb_method_entry_t *me = (rb_method_entry_t *) value;
781  st_table *tbl = (st_table *) data;
782 
783  if (me->def->type == VM_METHOD_TYPE_REFINED) {
784  if (me->def->body.orig_me) {
785  rb_method_entry_t *orig_me = me->def->body.orig_me, *new_me;
786  me->def->body.orig_me = NULL;
787  new_me = ALLOC(rb_method_entry_t);
788  *new_me = *me;
789  st_add_direct(tbl, key, (st_data_t) new_me);
790  *me = *orig_me;
791  xfree(orig_me);
792  return ST_CONTINUE;
793  }
794  else {
795  st_add_direct(tbl, key, (st_data_t) me);
796  return ST_DELETE;
797  }
798  }
799  else {
800  return ST_CONTINUE;
801  }
802 }
803 
804 void
806 {
808  VALUE origin;
809  int changed = 0;
810 
811  rb_frozen_class_p(klass);
812  if (!OBJ_UNTRUSTED(klass)) {
813  rb_secure(4);
814  }
815 
816  Check_Type(module, T_MODULE);
817 
818  OBJ_INFECT(klass, module);
819 
820  origin = RCLASS_ORIGIN(klass);
821  if (origin == klass) {
822  origin = class_alloc(T_ICLASS, klass);
823  RCLASS_SUPER(origin) = RCLASS_SUPER(klass);
824  RCLASS_SUPER(klass) = origin;
825  RCLASS_ORIGIN(klass) = origin;
826  RCLASS_M_TBL(origin) = RCLASS_M_TBL(klass);
827  RCLASS_M_TBL(klass) = st_init_numtable();
829  (st_data_t) RCLASS_M_TBL(klass));
830  }
831  changed = include_modules_at(klass, klass, module);
832  if (changed < 0)
833  rb_raise(rb_eArgError, "cyclic prepend detected");
834  if (changed) {
835  rb_clear_cache();
837  }
838 }
839 
840 /*
841  * call-seq:
842  * mod.included_modules -> array
843  *
844  * Returns the list of modules included in <i>mod</i>.
845  *
846  * module Mixin
847  * end
848  *
849  * module Outer
850  * include Mixin
851  * end
852  *
853  * Mixin.included_modules #=> []
854  * Outer.included_modules #=> [Mixin]
855  */
856 
857 VALUE
859 {
860  VALUE ary = rb_ary_new();
861  VALUE p;
862  VALUE origin = RCLASS_ORIGIN(mod);
863 
864  for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
865  if (p != origin && BUILTIN_TYPE(p) == T_ICLASS) {
866  VALUE m = RBASIC(p)->klass;
867  if (RB_TYPE_P(m, T_MODULE))
868  rb_ary_push(ary, m);
869  }
870  }
871  return ary;
872 }
873 
874 /*
875  * call-seq:
876  * mod.include?(module) -> true or false
877  *
878  * Returns <code>true</code> if <i>module</i> is included in
879  * <i>mod</i> or one of <i>mod</i>'s ancestors.
880  *
881  * module A
882  * end
883  * class B
884  * include A
885  * end
886  * class C < B
887  * end
888  * B.include?(A) #=> true
889  * C.include?(A) #=> true
890  * A.include?(A) #=> false
891  */
892 
893 VALUE
895 {
896  VALUE p;
897 
898  Check_Type(mod2, T_MODULE);
899  for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
900  if (BUILTIN_TYPE(p) == T_ICLASS) {
901  if (RBASIC(p)->klass == mod2) return Qtrue;
902  }
903  }
904  return Qfalse;
905 }
906 
907 /*
908  * call-seq:
909  * mod.ancestors -> array
910  *
911  * Returns a list of modules included in <i>mod</i> (including
912  * <i>mod</i> itself).
913  *
914  * module Mod
915  * include Math
916  * include Comparable
917  * end
918  *
919  * Mod.ancestors #=> [Mod, Comparable, Math]
920  * Math.ancestors #=> [Math]
921  */
922 
923 VALUE
925 {
926  VALUE p, ary = rb_ary_new();
927 
928  for (p = mod; p; p = RCLASS_SUPER(p)) {
929  if (FL_TEST(p, FL_SINGLETON))
930  continue;
931  if (BUILTIN_TYPE(p) == T_ICLASS) {
932  rb_ary_push(ary, RBASIC(p)->klass);
933  }
934  else if (p == RCLASS_ORIGIN(p)) {
935  rb_ary_push(ary, p);
936  }
937  }
938  return ary;
939 }
940 
941 #define VISI(x) ((x)&NOEX_MASK)
942 #define VISI_CHECK(x,f) (VISI(x) == (f))
943 
944 static int
945 ins_methods_push(ID name, long type, VALUE ary, long visi)
946 {
947  if (type == -1) return ST_CONTINUE;
948 
949  switch (visi) {
950  case NOEX_PRIVATE:
951  case NOEX_PROTECTED:
952  case NOEX_PUBLIC:
953  visi = (type == visi);
954  break;
955  default:
956  visi = (type != NOEX_PRIVATE);
957  break;
958  }
959  if (visi) {
960  rb_ary_push(ary, ID2SYM(name));
961  }
962  return ST_CONTINUE;
963 }
964 
965 static int
967 {
968  return ins_methods_push((ID)name, (long)type, (VALUE)ary, -1); /* everything but private */
969 }
970 
971 static int
973 {
974  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PROTECTED);
975 }
976 
977 static int
979 {
980  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PRIVATE);
981 }
982 
983 static int
985 {
986  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PUBLIC);
987 }
988 
989 static int
991 {
992  const rb_method_entry_t *me = (const rb_method_entry_t *)value;
993  st_table *list = (st_table *)data;
994  long type;
995 
996  if (me && me->def->type == VM_METHOD_TYPE_REFINED) {
998  if (!me) return ST_CONTINUE;
999  }
1000  if (!st_lookup(list, key, 0)) {
1001  if (UNDEFINED_METHOD_ENTRY_P(me)) {
1002  type = -1; /* none */
1003  }
1004  else {
1005  type = VISI(me->flag);
1006  }
1007  st_add_direct(list, key, type);
1008  }
1009  return ST_CONTINUE;
1010 }
1011 
1012 static VALUE
1014 {
1015  VALUE ary;
1016  int recur, prepended = 0;
1017  st_table *list;
1018 
1019  if (argc == 0) {
1020  recur = TRUE;
1021  }
1022  else {
1023  VALUE r;
1024  rb_scan_args(argc, argv, "01", &r);
1025  recur = RTEST(r);
1026  }
1027 
1028  if (!recur && RCLASS_ORIGIN(mod) != mod) {
1029  mod = RCLASS_ORIGIN(mod);
1030  prepended = 1;
1031  }
1032 
1033  list = st_init_numtable();
1034  for (; mod; mod = RCLASS_SUPER(mod)) {
1036  if (BUILTIN_TYPE(mod) == T_ICLASS && !prepended) continue;
1037  if (obj && FL_TEST(mod, FL_SINGLETON)) continue;
1038  if (!recur) break;
1039  }
1040  ary = rb_ary_new();
1041  st_foreach(list, func, ary);
1042  st_free_table(list);
1043 
1044  return ary;
1045 }
1046 
1047 /*
1048  * call-seq:
1049  * mod.instance_methods(include_super=true) -> array
1050  *
1051  * Returns an array containing the names of the public and protected instance
1052  * methods in the receiver. For a module, these are the public and protected methods;
1053  * for a class, they are the instance (not singleton) methods. With no
1054  * argument, or with an argument that is <code>false</code>, the
1055  * instance methods in <i>mod</i> are returned, otherwise the methods
1056  * in <i>mod</i> and <i>mod</i>'s superclasses are returned.
1057  *
1058  * module A
1059  * def method1() end
1060  * end
1061  * class B
1062  * def method2() end
1063  * end
1064  * class C < B
1065  * def method3() end
1066  * end
1067  *
1068  * A.instance_methods #=> [:method1]
1069  * B.instance_methods(false) #=> [:method2]
1070  * C.instance_methods(false) #=> [:method3]
1071  * C.instance_methods(true).length #=> 43
1072  */
1073 
1074 VALUE
1076 {
1077  return class_instance_method_list(argc, argv, mod, 0, ins_methods_i);
1078 }
1079 
1080 /*
1081  * call-seq:
1082  * mod.protected_instance_methods(include_super=true) -> array
1083  *
1084  * Returns a list of the protected instance methods defined in
1085  * <i>mod</i>. If the optional parameter is not <code>false</code>, the
1086  * methods of any ancestors are included.
1087  */
1088 
1089 VALUE
1091 {
1092  return class_instance_method_list(argc, argv, mod, 0, ins_methods_prot_i);
1093 }
1094 
1095 /*
1096  * call-seq:
1097  * mod.private_instance_methods(include_super=true) -> array
1098  *
1099  * Returns a list of the private instance methods defined in
1100  * <i>mod</i>. If the optional parameter is not <code>false</code>, the
1101  * methods of any ancestors are included.
1102  *
1103  * module Mod
1104  * def method1() end
1105  * private :method1
1106  * def method2() end
1107  * end
1108  * Mod.instance_methods #=> [:method2]
1109  * Mod.private_instance_methods #=> [:method1]
1110  */
1111 
1112 VALUE
1114 {
1115  return class_instance_method_list(argc, argv, mod, 0, ins_methods_priv_i);
1116 }
1117 
1118 /*
1119  * call-seq:
1120  * mod.public_instance_methods(include_super=true) -> array
1121  *
1122  * Returns a list of the public instance methods defined in <i>mod</i>.
1123  * If the optional parameter is not <code>false</code>, the methods of
1124  * any ancestors are included.
1125  */
1126 
1127 VALUE
1129 {
1130  return class_instance_method_list(argc, argv, mod, 0, ins_methods_pub_i);
1131 }
1132 
1133 /*
1134  * call-seq:
1135  * obj.methods(all=true) -> array
1136  *
1137  * Returns a list of the names of public and protected methods of
1138  * <i>obj</i>. This will include all the methods accessible in
1139  * <i>obj</i>'s ancestors.
1140  * If the <i>all</i> parameter is set to <code>false</code>, only those methods
1141  * in the receiver will be listed.
1142  *
1143  * class Klass
1144  * def klass_method()
1145  * end
1146  * end
1147  * k = Klass.new
1148  * k.methods[0..9] #=> [:klass_method, :nil?, :===,
1149  * # :==~, :!, :eql?
1150  * # :hash, :<=>, :class, :singleton_class]
1151  * k.methods.length #=> 57
1152  */
1153 
1154 VALUE
1155 rb_obj_methods(int argc, VALUE *argv, VALUE obj)
1156 {
1157  retry:
1158  if (argc == 0) {
1159  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_i);
1160  }
1161  else {
1162  VALUE recur;
1163 
1164  rb_scan_args(argc, argv, "1", &recur);
1165  if (RTEST(recur)) {
1166  argc = 0;
1167  goto retry;
1168  }
1169  return rb_obj_singleton_methods(argc, argv, obj);
1170  }
1171 }
1172 
1173 /*
1174  * call-seq:
1175  * obj.protected_methods(all=true) -> array
1176  *
1177  * Returns the list of protected methods accessible to <i>obj</i>. If
1178  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1179  * in the receiver will be listed.
1180  */
1181 
1182 VALUE
1183 rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj)
1184 {
1185  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_prot_i);
1186 }
1187 
1188 /*
1189  * call-seq:
1190  * obj.private_methods(all=true) -> array
1191  *
1192  * Returns the list of private methods accessible to <i>obj</i>. If
1193  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1194  * in the receiver will be listed.
1195  */
1196 
1197 VALUE
1198 rb_obj_private_methods(int argc, VALUE *argv, VALUE obj)
1199 {
1200  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_priv_i);
1201 }
1202 
1203 /*
1204  * call-seq:
1205  * obj.public_methods(all=true) -> array
1206  *
1207  * Returns the list of public methods accessible to <i>obj</i>. If
1208  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1209  * in the receiver will be listed.
1210  */
1211 
1212 VALUE
1213 rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
1214 {
1215  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_pub_i);
1216 }
1217 
1218 /*
1219  * call-seq:
1220  * obj.singleton_methods(all=true) -> array
1221  *
1222  * Returns an array of the names of singleton methods for <i>obj</i>.
1223  * If the optional <i>all</i> parameter is true, the list will include
1224  * methods in modules included in <i>obj</i>.
1225  * Only public and protected singleton methods are returned.
1226  *
1227  * module Other
1228  * def three() end
1229  * end
1230  *
1231  * class Single
1232  * def Single.four() end
1233  * end
1234  *
1235  * a = Single.new
1236  *
1237  * def a.one()
1238  * end
1239  *
1240  * class << a
1241  * include Other
1242  * def two()
1243  * end
1244  * end
1245  *
1246  * Single.singleton_methods #=> [:four]
1247  * a.singleton_methods(false) #=> [:two, :one]
1248  * a.singleton_methods #=> [:two, :one, :three]
1249  */
1250 
1251 VALUE
1252 rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
1253 {
1254  VALUE recur, ary, klass;
1255  st_table *list;
1256 
1257  if (argc == 0) {
1258  recur = Qtrue;
1259  }
1260  else {
1261  rb_scan_args(argc, argv, "01", &recur);
1262  }
1263  klass = CLASS_OF(obj);
1264  list = st_init_numtable();
1265  if (klass && FL_TEST(klass, FL_SINGLETON)) {
1266  if (RCLASS_M_TBL(klass))
1268  klass = RCLASS_SUPER(klass);
1269  }
1270  if (RTEST(recur)) {
1271  while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
1272  if (RCLASS_M_TBL(klass))
1274  klass = RCLASS_SUPER(klass);
1275  }
1276  }
1277  ary = rb_ary_new();
1278  st_foreach(list, ins_methods_i, ary);
1279  st_free_table(list);
1280 
1281  return ary;
1282 }
1283 
1341 void
1343 {
1344  rb_add_method_cfunc(klass, mid, func, argc, NOEX_PUBLIC);
1345 }
1346 
1347 void
1348 rb_define_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
1349 {
1350  rb_add_method_cfunc(klass, rb_intern(name), func, argc, NOEX_PUBLIC);
1351 }
1352 
1353 void
1354 rb_define_protected_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
1355 {
1356  rb_add_method_cfunc(klass, rb_intern(name), func, argc, NOEX_PROTECTED);
1357 }
1358 
1359 void
1360 rb_define_private_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
1361 {
1362  rb_add_method_cfunc(klass, rb_intern(name), func, argc, NOEX_PRIVATE);
1363 }
1364 
1365 void
1366 rb_undef_method(VALUE klass, const char *name)
1367 {
1369 }
1370 
1379 #define SPECIAL_SINGLETON(x,c) do {\
1380  if (obj == (x)) {\
1381  return (c);\
1382  }\
1383 } while (0)
1384 
1385 static inline VALUE
1387 {
1391  return Qnil;
1392 }
1393 
1394 VALUE
1396 {
1397  return special_singleton_class_of(obj);
1398 }
1399 
1409 static VALUE
1411 {
1412  VALUE klass;
1413 
1414  if (FIXNUM_P(obj) || FLONUM_P(obj) || SYMBOL_P(obj)) {
1415  rb_raise(rb_eTypeError, "can't define singleton");
1416  }
1417  if (SPECIAL_CONST_P(obj)) {
1418  klass = special_singleton_class_of(obj);
1419  if (NIL_P(klass))
1420  rb_bug("unknown immediate %p", (void *)obj);
1421  return klass;
1422  }
1423  else {
1424  enum ruby_value_type type = BUILTIN_TYPE(obj);
1425  if (type == T_FLOAT || type == T_BIGNUM) {
1426  rb_raise(rb_eTypeError, "can't define singleton");
1427  }
1428  }
1429 
1430  if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) &&
1431  rb_ivar_get(RBASIC(obj)->klass, id_attached) == obj) {
1432  klass = RBASIC(obj)->klass;
1433  }
1434  else {
1435  klass = rb_make_metaclass(obj, RBASIC(obj)->klass);
1436  }
1437 
1438  if (OBJ_TAINTED(obj)) {
1439  OBJ_TAINT(klass);
1440  }
1441  else {
1442  FL_UNSET(klass, FL_TAINT);
1443  }
1444  if (OBJ_UNTRUSTED(obj)) {
1445  OBJ_UNTRUST(klass);
1446  }
1447  else {
1448  FL_UNSET(klass, FL_UNTRUSTED);
1449  }
1450  if (OBJ_FROZEN(obj)) OBJ_FREEZE(klass);
1451 
1452  return klass;
1453 }
1454 
1455 
1473 VALUE
1475 {
1476  VALUE klass = singleton_class_of(obj);
1477 
1478  /* ensures an exposed class belongs to its own eigenclass */
1479  if (RB_TYPE_P(obj, T_CLASS)) (void)ENSURE_EIGENCLASS(klass);
1480 
1481  return klass;
1482 }
1483 
1500 void
1501 rb_define_singleton_method(VALUE obj, const char *name, VALUE (*func)(ANYARGS), int argc)
1502 {
1503  rb_define_method(singleton_class_of(obj), name, func, argc);
1504 }
1505 
1506 
1507 
1515 void
1516 rb_define_module_function(VALUE module, const char *name, VALUE (*func)(ANYARGS), int argc)
1517 {
1518  rb_define_private_method(module, name, func, argc);
1519  rb_define_singleton_method(module, name, func, argc);
1520 }
1521 
1522 
1529 void
1530 rb_define_global_function(const char *name, VALUE (*func)(ANYARGS), int argc)
1531 {
1533 }
1534 
1535 
1542 void
1543 rb_define_alias(VALUE klass, const char *name1, const char *name2)
1544 {
1545  rb_alias(klass, rb_intern(name1), rb_intern(name2));
1546 }
1547 
1555 void
1556 rb_define_attr(VALUE klass, const char *name, int read, int write)
1557 {
1558  rb_attr(klass, rb_intern(name), read, write, FALSE);
1559 }
1560 
1561 int
1563 {
1564  const rb_method_entry_t *me = rb_method_entry(CLASS_OF(obj), rb_intern("to_s"), 0);
1565  if (me && me->def && me->def->type == VM_METHOD_TYPE_CFUNC &&
1566  me->def->body.cfunc.func == rb_any_to_s)
1567  return 1;
1568  return 0;
1569 }
1570 
1571 #include <stdarg.h>
1572 
1573 int
1574 rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
1575 {
1576  int i;
1577  const char *p = fmt;
1578  VALUE *var;
1579  va_list vargs;
1580  int f_var = 0, f_hash = 0, f_block = 0;
1581  int n_lead = 0, n_opt = 0, n_trail = 0, n_mand;
1582  int argi = 0;
1583  VALUE hash = Qnil;
1584 
1585  if (ISDIGIT(*p)) {
1586  n_lead = *p - '0';
1587  p++;
1588  if (ISDIGIT(*p)) {
1589  n_opt = *p - '0';
1590  p++;
1591  if (ISDIGIT(*p)) {
1592  n_trail = *p - '0';
1593  p++;
1594  goto block_arg;
1595  }
1596  }
1597  }
1598  if (*p == '*') {
1599  f_var = 1;
1600  p++;
1601  if (ISDIGIT(*p)) {
1602  n_trail = *p - '0';
1603  p++;
1604  }
1605  }
1606  block_arg:
1607  if (*p == ':') {
1608  f_hash = 1;
1609  p++;
1610  }
1611  if (*p == '&') {
1612  f_block = 1;
1613  p++;
1614  }
1615  if (*p != '\0') {
1616  rb_fatal("bad scan arg format: %s", fmt);
1617  }
1618  n_mand = n_lead + n_trail;
1619 
1620  if (argc < n_mand)
1621  goto argc_error;
1622 
1623  va_start(vargs, fmt);
1624 
1625  /* capture an option hash - phase 1: pop */
1626  if (f_hash && n_mand < argc) {
1627  VALUE last = argv[argc - 1];
1628 
1629  if (NIL_P(last)) {
1630  /* nil is taken as an empty option hash only if it is not
1631  ambiguous; i.e. '*' is not specified and arguments are
1632  given more than sufficient */
1633  if (!f_var && n_mand + n_opt < argc)
1634  argc--;
1635  }
1636  else {
1637  hash = rb_check_hash_type(last);
1638  if (!NIL_P(hash))
1639  argc--;
1640  }
1641  }
1642  /* capture leading mandatory arguments */
1643  for (i = n_lead; i-- > 0; ) {
1644  var = va_arg(vargs, VALUE *);
1645  if (var) *var = argv[argi];
1646  argi++;
1647  }
1648  /* capture optional arguments */
1649  for (i = n_opt; i-- > 0; ) {
1650  var = va_arg(vargs, VALUE *);
1651  if (argi < argc - n_trail) {
1652  if (var) *var = argv[argi];
1653  argi++;
1654  }
1655  else {
1656  if (var) *var = Qnil;
1657  }
1658  }
1659  /* capture variable length arguments */
1660  if (f_var) {
1661  int n_var = argc - argi - n_trail;
1662 
1663  var = va_arg(vargs, VALUE *);
1664  if (0 < n_var) {
1665  if (var) *var = rb_ary_new4(n_var, &argv[argi]);
1666  argi += n_var;
1667  }
1668  else {
1669  if (var) *var = rb_ary_new();
1670  }
1671  }
1672  /* capture trailing mandatory arguments */
1673  for (i = n_trail; i-- > 0; ) {
1674  var = va_arg(vargs, VALUE *);
1675  if (var) *var = argv[argi];
1676  argi++;
1677  }
1678  /* capture an option hash - phase 2: assignment */
1679  if (f_hash) {
1680  var = va_arg(vargs, VALUE *);
1681  if (var) *var = hash;
1682  }
1683  /* capture iterator block */
1684  if (f_block) {
1685  var = va_arg(vargs, VALUE *);
1686  if (rb_block_given_p()) {
1687  *var = rb_block_proc();
1688  }
1689  else {
1690  *var = Qnil;
1691  }
1692  }
1693  va_end(vargs);
1694 
1695  if (argi < argc) {
1696  argc_error:
1697  rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt);
1698  }
1699 
1700  return argc;
1701 }
1702 
VALUE data
Definition: tcltklib.c:3367
static VALUE make_metaclass(VALUE klass)
Creates a metaclass of klass.
Definition: class.c:344
#define RB_TYPE_P(obj, type)
VALUE rb_const_get_at(VALUE, ID)
Definition: variable.c:1882
#define ALLOC(type)
volatile VALUE tmp
Definition: tcltklib.c:10208
#define UNDEFINED_METHOD_ENTRY_P(me)
Definition: method.h:108
VALUE rb_define_module_id_under(VALUE outer, ID id)
Definition: class.c:647
volatile VALUE ary
Definition: tcltklib.c:9712
#define FLONUM_P(x)
RUBY_EXTERN VALUE rb_cBasicObject
Definition: ripper.y:1425
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
VALUE rb_mod_include_p(VALUE mod, VALUE mod2)
Definition: class.c:894
VALUE rb_any_to_s(VALUE)
Definition: object.c:393
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
RUBY_EXTERN VALUE rb_cNilClass
Definition: ripper.y:1447
RUBY_EXTERN VALUE rb_cModule
Definition: ripper.y:1445
#define OBJ_INFECT(x, s)
static int ins_methods_push(ID name, long type, VALUE ary, long visi)
Definition: class.c:945
static ID id_attached
Definition: class.c:35
Definition: constant.h:19
const char * rb_obj_classname(VALUE)
Definition: variable.c:396
VALUE rb_obj_private_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1198
VALUE rb_id2str(ID id)
Definition: ripper.c:16940
Win32OLEIDispatch * p
Definition: win32ole.c:786
#define VISI(x)
Definition: class.c:941
#define UNLIMITED_ARGUMENTS
#define FL_TEST(x, f)
static NODE * rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass)
Definition: class.c:125
int st_lookup(st_table *, st_data_t, st_data_t *)
void st_add_direct(st_table *, st_data_t, st_data_t)
Definition: st.c:629
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1501
rb_method_flag_t flag
Definition: method.h:96
#define FL_SET(x, f)
st_table * st_init_numtable(void)
Definition: st.c:272
VALUE rb_class_private_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1113
#define T_ICLASS
VALUE rb_define_class_id_under(VALUE outer, ID id, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:572
#define RMODULE_M_TBL(m)
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:108
void rb_secure(int)
Definition: safe.c:79
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:1876
static VALUE class_alloc(VALUE flags, VALUE klass)
Allocates a struct RClass for a new class.
Definition: class.c:50
ssize_t i
Definition: bigdecimal.c:5676
struct rb_method_entry_struct * orig_me
Definition: method.h:90
VALUE rb_mod_ancestors(VALUE mod)
Definition: class.c:924
VALUE rb_refinement_module_get_refined_class(VALUE module)
Definition: eval.c:1122
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1360
#define RCLASS_ORIGIN(c)
VALUE rb_eTypeError
Definition: error.c:516
#define OBJ_FREEZE(x)
#define OBJ_TAINTED(x)
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:822
VALUE rb_singleton_class_clone(VALUE obj)
Definition: class.c:245
RUBY_EXTERN VALUE rb_cTrueClass
Definition: ripper.y:1461
VALUE rb_mod_init_copy(VALUE clone, VALUE orig)
Definition: class.c:196
#define CLASS_OF(v)
NIL_P(eventloop_thread)
Definition: tcltklib.c:4067
VALUE var
Definition: tcltklib.c:5516
void Init_class_hierarchy(void)
Definition: class.c:405
#define xfree
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:773
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:549
static int ins_methods_priv_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:978
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1788
return Qtrue
Definition: tcltklib.c:9609
static int clone_const_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:175
#define NEW_CREF(a)
union rb_method_definition_struct::@112 body
void rb_include_module(VALUE klass, VALUE module)
Definition: class.c:699
r
Definition: bigdecimal.c:1210
#define FL_UNTRUSTED
void rb_define_protected_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1354
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1530
#define ISDIGIT(c)
ruby_value_type
Definition: ripper.y:450
unsigned int last
Definition: nkf.c:4310
#define ID2SYM(x)
#define T_FLOAT
VALUE tbl
Definition: tkutil.c:1279
void rb_undef_method(VALUE klass, const char *name)
Definition: class.c:1366
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1116
const char * fmt
Definition: tcltklib.c:841
#define RCLASS_EXT(c)
void rb_name_error(ID id, const char *fmt,...)
Definition: error.c:904
Definition: ripper.y:240
char * name2
Definition: tcltklib.c:4205
void rb_prepend_module(VALUE klass, VALUE module)
Definition: class.c:805
unsigned long st_data_t
Definition: ripper.y:35
int st_delete(st_table *, st_data_t *, st_data_t *)
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1474
VALUE hash
Definition: tkutil.c:267
rb_method_cfunc_t cfunc
Definition: method.h:81
VALUE rb_block_proc(void)
Definition: proc.c:458
VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
Definition: class.c:477
BDIGIT m
Definition: bigdecimal.c:5106
#define FIXNUM_P(f)
return Qfalse
Definition: tcltklib.c:6778
NODE * cref_stack
Definition: vm_core.h:304
int rb_block_given_p(void)
Definition: eval.c:672
#define Qnil
Definition: tcltklib.c:1895
VALUE rb_special_singleton_class(VALUE obj)
Definition: class.c:1395
#define RCLASS_IV_TBL(c)
RUBY_EXTERN VALUE rb_mKernel
Definition: ripper.y:1414
static VALUE boot_defclass(const char *name, VALUE super)
Definition: class.c:392
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:142
#define Check_Type(v, t)
int flags
Definition: tcltklib.c:3022
unsigned long ID
Definition: ripper.y:105
va_end(args)
#define RCLASS_SUPER(c)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:503
static VALUE VALUE obj
Definition: tcltklib.c:3157
static VALUE special_singleton_class_of(VALUE obj)
Definition: class.c:1386
void rb_clear_cache(void)
Definition: vm_method.c:46
VALUE rb_define_module_id(ID id)
Definition: class.c:610
#define METACLASS_OF(k)
Definition: class.c:305
#define ANYARGS
#define META_CLASS_OF_CLASS_CLASS_P(k)
whether k is a meta^(n)-class of Class class
Definition: class.c:312
#define OBJ_INIT_COPY(obj, orig)
Definition: method.h:95
VALUE rb_check_hash_type(VALUE)
Definition: hash.c:461
VALUE rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1183
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
static int VALUE key
Definition: tkutil.c:265
rb_method_entry_t * rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr)
Definition: vm_method.c:572
VALUE(* func)(ANYARGS)
Definition: method.h:64
VALUE klass
Definition: method.h:100
int rb_obj_basic_to_s_p(VALUE obj)
Definition: class.c:1562
VALUE * argv
Definition: tcltklib.c:1970
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
Definition: class.c:1543
#define RTEST(v)
const int id
Definition: nkf.c:209
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
Definition: class.c:1516
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
Definition: st.c:1006
static int add_refined_method_entry_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:721
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:1013
#define TRUE
Definition: nkf.h:175
volatile VALUE value
Definition: tcltklib.c:9441
va_list vargs
Definition: regerror.c:269
int rb_const_defined(VALUE, ID)
Definition: variable.c:2103
VALUE rb_include_class_new(VALUE module, VALUE super)
Definition: class.c:667
void rb_fatal(const char *fmt,...)
Definition: error.c:1842
char * name1
Definition: tcltklib.c:4204
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
#define CONST_ID(var, str)
void rb_gc_register_mark_object(VALUE)
Definition: gc.c:2982
VP_EXPORT void
Definition: bigdecimal.c:5104
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1574
void rb_attr(VALUE, ID, int, int, int)
Definition: vm_method.c:817
static int ins_methods_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:966
void rb_const_set(VALUE, ID, VALUE)
Definition: variable.c:2141
#define OBJ_FROZEN(x)
#define RB_GC_GUARD(v)
int type
Definition: tcltklib.c:111
#define FL_TAINT
static int include_modules_at(const VALUE klass, VALUE c, VALUE module)
Definition: class.c:728
VALUE rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1213
static int ins_methods_pub_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:984
int argc
Definition: tcltklib.c:1969
void rb_alias(VALUE, ID, ID)
Definition: vm_method.c:1203
int rb_const_defined_at(VALUE, ID)
Definition: variable.c:2109
VALUE rb_make_metaclass(VALUE obj, VALUE unused)
Definition: class.c:434
VpDivd * c
Definition: bigdecimal.c:1219
VALUE rb_class_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1075
void rb_free_const_table(st_table *tbl)
Definition: gc.c:814
#define T_BIGNUM
#define RCLASS_CONST_TBL(c)
VALUE rb_define_module_under(VALUE outer, const char *name)
Definition: class.c:641
#define recur(fmt)
const char * rb_class2name(VALUE)
Definition: variable.c:389
VALUE rb_class_protected_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1090
#define NEWOBJ_OF(obj, type, klass, flags)
void rb_define_method_id(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1342
VALUE rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1128
void rb_singleton_class_attached(VALUE klass, VALUE obj)
Attach a object to a singleton class.
Definition: class.c:293
#define SYMBOL_P(x)
#define FL_SINGLETON
VALUE rb_module_new(void)
Definition: class.c:600
#define Qundef
#define T_CLASS
#define ENSURE_EIGENCLASS(klass)
ensures klass belongs to its own eigenclass.
Definition: class.c:330
VALUE rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1252
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:1556
void rb_error_arity(int argc, int min, int max)
RUBY_EXTERN VALUE rb_cClass
Definition: ripper.y:1430
RUBY_EXTERN VALUE rb_cObject
Definition: ripper.y:1426
static VALUE make_singleton_class(VALUE obj)
Creates a singleton class for obj.
Definition: class.c:377
#define RBASIC(obj)
klass
Definition: tcltklib.c:3503
static int method_entry_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:990
struct rb_encoding_entry * list
Definition: encoding.c:50
VALUE rb_obj_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1155
void rb_add_refined_method_entry(VALUE refined_class, ID mid)
Definition: vm_method.c:212
int st_insert(st_table *, st_data_t, st_data_t)
static int ins_methods_prot_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:972
void rb_set_class_path_string(VALUE, VALUE, VALUE)
Definition: variable.c:285
#define OBJ_UNTRUST(x)
static int move_refined_method(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:778
#define T_MODULE
void rb_frozen_class_p(VALUE klass)
Definition: eval.c:403
#define RCLASS_IV_INDEX_TBL(c)
static void class_init_copy_check(VALUE clone, VALUE orig)
Definition: class.c:181
VALUE self
Definition: vm_core.h:292
#define GetISeqPtr(obj, ptr)
Definition: vm_core.h:183
const char * rb_id2name(ID id)
Definition: ripper.c:17006
VALUE rb_mod_included_modules(VALUE mod)
Definition: class.c:858
#define BUILTIN_TYPE(x)
VALUE rb_class_real(VALUE)
Definition: object.c:171
#define OBJ_UNTRUSTED(x)
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:456
unsigned long VALUE
Definition: ripper.y:104
#define SPECIAL_SINGLETON(x, c)
Definition: class.c:1379
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
st_table * st_copy(st_table *)
Definition: st.c:663
#define RMODULE_IS_REFINEMENT
#define SPECIAL_CONST_P(x)
#define OBJ_TAINT(x)
VALUE rb_define_module(const char *name)
Definition: class.c:621
RUBY_EXTERN VALUE rb_cFalseClass
Definition: ripper.y:1434
void rb_name_class(VALUE, ID)
Definition: variable.c:377
#define rb_intern(str)
static int clone_const(ID key, const rb_const_entry_t *ce, st_table *tbl)
Definition: class.c:166
#define mod(x, y)
Definition: date_strftime.c:28
#define RCLASS_M_TBL(c)
#define NULL
Definition: _sdbm.c:103
static VALUE singleton_class_of(VALUE obj)
Definition: class.c:1410
Definition: ripper.y:737
static int clone_method_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:159
#define RCLASS_REFINED_CLASS(c)
const char * name
Definition: nkf.c:208
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_iseq_clone(VALUE iseqval, VALUE newcbase)
Definition: iseq.c:1900
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:1348
int retry
Definition: tcltklib.c:10150
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
VALUE rb_eArgError
Definition: error.c:517
void rb_free_m_table(st_table *tbl)
Definition: gc.c:800
void st_free_table(st_table *)
Definition: st.c:334
#define RMODULE_CONST_TBL(m)
#define FL_UNSET(x, f)
VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
Definition: class.c:251
#define RMODULE_INCLUDED_INTO_REFINEMENT