Ruby  2.0.0p247(2013-06-27revision41674)
class.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  class.c -
4 
5  $Author: nagachika $
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  rb_obj_init_copy(clone, orig);
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(orig)) {
209  st_data_t id;
210 
211  if (RCLASS_IV_TBL(clone)) {
213  }
214  RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(orig));
215  CONST_ID(id, "__tmp_classpath__");
216  st_delete(RCLASS_IV_TBL(clone), &id, 0);
217  CONST_ID(id, "__classpath__");
218  st_delete(RCLASS_IV_TBL(clone), &id, 0);
219  CONST_ID(id, "__classid__");
220  st_delete(RCLASS_IV_TBL(clone), &id, 0);
221  }
222  if (RCLASS_CONST_TBL(orig)) {
223  if (RCLASS_CONST_TBL(clone)) {
225  }
228  }
229  if (RCLASS_M_TBL(orig)) {
230  if (RCLASS_M_TBL(clone)) {
232  }
233  RCLASS_M_TBL(clone) = st_init_numtable();
235  }
236 
237  return clone;
238 }
239 
240 VALUE
242 {
244 }
245 
246 VALUE
248 {
249  VALUE klass = RBASIC(obj)->klass;
250 
251  if (!FL_TEST(klass, FL_SINGLETON))
252  return klass;
253  else {
254  /* copy singleton(unnamed) class */
255  VALUE clone = class_alloc(RBASIC(klass)->flags, 0);
256 
257  if (BUILTIN_TYPE(obj) == T_CLASS) {
258  RBASIC(clone)->klass = clone;
259  }
260  else {
261  RBASIC(clone)->klass = rb_singleton_class_clone(klass);
262  }
263 
264  RCLASS_SUPER(clone) = RCLASS_SUPER(klass);
265  RCLASS_EXT(clone)->allocator = RCLASS_EXT(klass)->allocator;
266  if (RCLASS_IV_TBL(klass)) {
267  RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(klass));
268  }
269  if (RCLASS_CONST_TBL(klass)) {
272  }
273  if (attach != Qundef) {
274  rb_singleton_class_attached(clone, attach);
275  }
276  RCLASS_M_TBL(clone) = st_init_numtable();
278  rb_singleton_class_attached(RBASIC(clone)->klass, clone);
279  FL_SET(clone, FL_SINGLETON);
280  return clone;
281  }
282 }
283 
288 void
290 {
291  if (FL_TEST(klass, FL_SINGLETON)) {
292  if (!RCLASS_IV_TBL(klass)) {
293  RCLASS_IV_TBL(klass) = st_init_numtable();
294  }
295  st_insert(RCLASS_IV_TBL(klass), id_attached, obj);
296  }
297 }
298 
299 
300 
301 #define METACLASS_OF(k) RBASIC(k)->klass
302 
308 #define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k))
309 
315 #define HAVE_METACLASS_P(k) \
316  (FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \
317  rb_ivar_get(METACLASS_OF(k), id_attached) == (k))
318 
326 #define ENSURE_EIGENCLASS(klass) \
327  (HAVE_METACLASS_P(klass) ? METACLASS_OF(klass) : make_metaclass(klass))
328 
329 
339 static inline VALUE
341 {
342  VALUE super;
343  VALUE metaclass = rb_class_boot(Qundef);
344 
345  FL_SET(metaclass, FL_SINGLETON);
346  rb_singleton_class_attached(metaclass, klass);
347 
348  if (META_CLASS_OF_CLASS_CLASS_P(klass)) {
349  METACLASS_OF(klass) = METACLASS_OF(metaclass) = metaclass;
350  }
351  else {
352  VALUE tmp = METACLASS_OF(klass); /* for a meta^(n)-class klass, tmp is meta^(n)-class of Class class */
353  METACLASS_OF(klass) = metaclass;
354  METACLASS_OF(metaclass) = ENSURE_EIGENCLASS(tmp);
355  }
356 
357  super = RCLASS_SUPER(klass);
358  while (RB_TYPE_P(super, T_ICLASS)) super = RCLASS_SUPER(super);
359  RCLASS_SUPER(metaclass) = super ? ENSURE_EIGENCLASS(super) : rb_cClass;
360 
361  OBJ_INFECT(metaclass, RCLASS_SUPER(metaclass));
362 
363  return metaclass;
364 }
365 
372 static inline VALUE
374 {
375  VALUE orig_class = RBASIC(obj)->klass;
376  VALUE klass = rb_class_boot(orig_class);
377 
378  FL_SET(klass, FL_SINGLETON);
379  RBASIC(obj)->klass = klass;
380  rb_singleton_class_attached(klass, obj);
381 
382  METACLASS_OF(klass) = METACLASS_OF(rb_class_real(orig_class));
383  return klass;
384 }
385 
386 
387 static VALUE
388 boot_defclass(const char *name, VALUE super)
389 {
390  extern st_table *rb_class_tbl;
391  VALUE obj = rb_class_boot(super);
392  ID id = rb_intern(name);
393 
394  rb_name_class(obj, id);
395  st_add_direct(rb_class_tbl, id, obj);
396  rb_const_set((rb_cObject ? rb_cObject : obj), id, obj);
397  return obj;
398 }
399 
400 void
402 {
403  id_attached = rb_intern("__attached__");
404 
405  rb_cBasicObject = boot_defclass("BasicObject", 0);
407  rb_cModule = boot_defclass("Module", rb_cObject);
408  rb_cClass = boot_defclass("Class", rb_cModule);
409 
411  RBASIC(rb_cClass)->klass
412  = RBASIC(rb_cModule)->klass
413  = RBASIC(rb_cObject)->klass
414  = RBASIC(rb_cBasicObject)->klass
415  = rb_cClass;
416 }
417 
418 
429 VALUE
431 {
432  if (BUILTIN_TYPE(obj) == T_CLASS) {
433  return make_metaclass(obj);
434  }
435  else {
436  return make_singleton_class(obj);
437  }
438 }
439 
440 
451 VALUE
453 {
454  VALUE klass;
455 
456  if (!super) super = rb_cObject;
457  klass = rb_class_new(super);
458  rb_make_metaclass(klass, RBASIC(super)->klass);
459 
460  return klass;
461 }
462 
463 
472 VALUE
474 {
475  ID inherited;
476  if (!super) super = rb_cObject;
477  CONST_ID(inherited, "inherited");
478  return rb_funcall(super, inherited, 1, klass);
479 }
480 
481 
482 
498 VALUE
499 rb_define_class(const char *name, VALUE super)
500 {
501  VALUE klass;
502  ID id;
503 
504  id = rb_intern(name);
505  if (rb_const_defined(rb_cObject, id)) {
506  klass = rb_const_get(rb_cObject, id);
507  if (!RB_TYPE_P(klass, T_CLASS)) {
508  rb_raise(rb_eTypeError, "%s is not a class", name);
509  }
510  if (rb_class_real(RCLASS_SUPER(klass)) != super) {
511  rb_raise(rb_eTypeError, "superclass mismatch for class %s", name);
512  }
513  return klass;
514  }
515  if (!super) {
516  rb_warn("no super class for `%s', Object assumed", name);
517  }
518  klass = rb_define_class_id(id, super);
519  st_add_direct(rb_class_tbl, id, klass);
520  rb_name_class(klass, id);
521  rb_const_set(rb_cObject, id, klass);
522  rb_class_inherited(super, klass);
523 
524  return klass;
525 }
526 
527 
544 VALUE
545 rb_define_class_under(VALUE outer, const char *name, VALUE super)
546 {
547  return rb_define_class_id_under(outer, rb_intern(name), super);
548 }
549 
550 
567 VALUE
569 {
570  VALUE klass;
571 
572  if (rb_const_defined_at(outer, id)) {
573  klass = rb_const_get_at(outer, id);
574  if (!RB_TYPE_P(klass, T_CLASS)) {
575  rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
576  }
577  if (rb_class_real(RCLASS_SUPER(klass)) != super) {
578  rb_name_error(id, "%s is already defined", rb_id2name(id));
579  }
580  return klass;
581  }
582  if (!super) {
583  rb_warn("no super class for `%s::%s', Object assumed",
584  rb_class2name(outer), rb_id2name(id));
585  }
586  klass = rb_define_class_id(id, super);
587  rb_set_class_path_string(klass, outer, rb_id2str(id));
588  rb_const_set(outer, id, klass);
589  rb_class_inherited(super, klass);
591 
592  return klass;
593 }
594 
595 VALUE
597 {
599 
601 
602  return (VALUE)mdl;
603 }
604 
605 VALUE
607 {
608  VALUE mdl;
609 
610  mdl = rb_module_new();
611  rb_name_class(mdl, id);
612 
613  return mdl;
614 }
615 
616 VALUE
617 rb_define_module(const char *name)
618 {
619  VALUE module;
620  ID id;
621 
622  id = rb_intern(name);
623  if (rb_const_defined(rb_cObject, id)) {
624  module = rb_const_get(rb_cObject, id);
625  if (RB_TYPE_P(module, T_MODULE))
626  return module;
627  rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module));
628  }
629  module = rb_define_module_id(id);
630  st_add_direct(rb_class_tbl, id, module);
631  rb_const_set(rb_cObject, id, module);
632 
633  return module;
634 }
635 
636 VALUE
637 rb_define_module_under(VALUE outer, const char *name)
638 {
639  return rb_define_module_id_under(outer, rb_intern(name));
640 }
641 
642 VALUE
644 {
645  VALUE module;
646 
647  if (rb_const_defined_at(outer, id)) {
648  module = rb_const_get_at(outer, id);
649  if (RB_TYPE_P(module, T_MODULE))
650  return module;
651  rb_raise(rb_eTypeError, "%s::%s is not a module",
652  rb_class2name(outer), rb_obj_classname(module));
653  }
654  module = rb_define_module_id(id);
655  rb_const_set(outer, id, module);
656  rb_set_class_path_string(module, outer, rb_id2str(id));
658 
659  return module;
660 }
661 
662 VALUE
664 {
666 
667  if (BUILTIN_TYPE(module) == T_ICLASS) {
668  module = RBASIC(module)->klass;
669  }
670  if (!RCLASS_IV_TBL(module)) {
671  RCLASS_IV_TBL(module) = st_init_numtable();
672  }
673  if (!RCLASS_CONST_TBL(module)) {
675  }
676  RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
677  RCLASS_CONST_TBL(klass) = RCLASS_CONST_TBL(module);
678  RCLASS_M_TBL(klass) = RCLASS_M_TBL(RCLASS_ORIGIN(module));
679  RCLASS_SUPER(klass) = super;
680  if (RB_TYPE_P(module, T_ICLASS)) {
681  RBASIC(klass)->klass = RBASIC(module)->klass;
682  }
683  else {
684  RBASIC(klass)->klass = module;
685  }
686  OBJ_INFECT(klass, module);
687  OBJ_INFECT(klass, super);
688 
689  return (VALUE)klass;
690 }
691 
692 static int include_modules_at(const VALUE klass, VALUE c, VALUE module);
693 
694 void
696 {
697  int changed = 0;
698 
699  rb_frozen_class_p(klass);
700  if (!OBJ_UNTRUSTED(klass)) {
701  rb_secure(4);
702  }
703 
704  if (!RB_TYPE_P(module, T_MODULE)) {
705  Check_Type(module, T_MODULE);
706  }
707 
708  OBJ_INFECT(klass, module);
709 
710  changed = include_modules_at(klass, RCLASS_ORIGIN(klass), module);
711  if (changed < 0)
712  rb_raise(rb_eArgError, "cyclic include detected");
713  if (changed) rb_clear_cache();
714 }
715 
716 static int
718 {
719  rb_add_refined_method_entry((VALUE) data, (ID) key);
720  return ST_CONTINUE;
721 }
722 
723 static int
725 {
726  VALUE p;
727  int changed = 0;
728  const st_table *const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass));
729 
730  while (module) {
731  int superclass_seen = FALSE;
732 
733  if (RCLASS_ORIGIN(module) != module)
734  goto skip;
735  if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module))
736  return -1;
737  /* ignore if the module included already in superclasses */
738  for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
739  switch (BUILTIN_TYPE(p)) {
740  case T_ICLASS:
741  if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
742  if (!superclass_seen) {
743  c = p; /* move insertion point */
744  }
745  goto skip;
746  }
747  break;
748  case T_CLASS:
749  superclass_seen = TRUE;
750  break;
751  }
752  }
753  c = RCLASS_SUPER(c) = rb_include_class_new(module, RCLASS_SUPER(c));
754  if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
755  VALUE refined_class =
757 
759  (st_data_t) refined_class);
761  }
762  if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
763  changed = 1;
764  if (RMODULE_CONST_TBL(module) && RMODULE_CONST_TBL(module)->num_entries)
765  changed = 1;
766  skip:
767  module = RCLASS_SUPER(module);
768  }
769 
770  return changed;
771 }
772 
773 static int
775 {
776  rb_method_entry_t *me = (rb_method_entry_t *) value;
777  st_table *tbl = (st_table *) data;
778 
779  if (me->def->type == VM_METHOD_TYPE_REFINED) {
780  if (me->def->body.orig_me) {
781  rb_method_entry_t *orig_me = me->def->body.orig_me, *new_me;
782  me->def->body.orig_me = NULL;
783  new_me = ALLOC(rb_method_entry_t);
784  *new_me = *me;
785  st_add_direct(tbl, key, (st_data_t) new_me);
786  *me = *orig_me;
787  xfree(orig_me);
788  return ST_CONTINUE;
789  }
790  else {
791  st_add_direct(tbl, key, (st_data_t) me);
792  return ST_DELETE;
793  }
794  }
795  else {
796  return ST_CONTINUE;
797  }
798 }
799 
800 void
802 {
804  VALUE origin;
805  int changed = 0;
806 
807  rb_frozen_class_p(klass);
808  if (!OBJ_UNTRUSTED(klass)) {
809  rb_secure(4);
810  }
811 
812  Check_Type(module, T_MODULE);
813 
814  OBJ_INFECT(klass, module);
815 
816  origin = RCLASS_ORIGIN(klass);
817  if (origin == klass) {
818  origin = class_alloc(T_ICLASS, klass);
819  RCLASS_SUPER(origin) = RCLASS_SUPER(klass);
820  RCLASS_SUPER(klass) = origin;
821  RCLASS_ORIGIN(klass) = origin;
822  RCLASS_M_TBL(origin) = RCLASS_M_TBL(klass);
823  RCLASS_M_TBL(klass) = st_init_numtable();
825  (st_data_t) RCLASS_M_TBL(klass));
826  }
827  changed = include_modules_at(klass, klass, module);
828  if (changed < 0)
829  rb_raise(rb_eArgError, "cyclic prepend detected");
830  if (changed) {
831  rb_clear_cache();
833  }
834 }
835 
836 /*
837  * call-seq:
838  * mod.included_modules -> array
839  *
840  * Returns the list of modules included in <i>mod</i>.
841  *
842  * module Mixin
843  * end
844  *
845  * module Outer
846  * include Mixin
847  * end
848  *
849  * Mixin.included_modules #=> []
850  * Outer.included_modules #=> [Mixin]
851  */
852 
853 VALUE
855 {
856  VALUE ary = rb_ary_new();
857  VALUE p;
858  VALUE origin = RCLASS_ORIGIN(mod);
859 
860  for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
861  if (p != origin && BUILTIN_TYPE(p) == T_ICLASS) {
862  VALUE m = RBASIC(p)->klass;
863  if (RB_TYPE_P(m, T_MODULE))
864  rb_ary_push(ary, m);
865  }
866  }
867  return ary;
868 }
869 
870 /*
871  * call-seq:
872  * mod.include?(module) -> true or false
873  *
874  * Returns <code>true</code> if <i>module</i> is included in
875  * <i>mod</i> or one of <i>mod</i>'s ancestors.
876  *
877  * module A
878  * end
879  * class B
880  * include A
881  * end
882  * class C < B
883  * end
884  * B.include?(A) #=> true
885  * C.include?(A) #=> true
886  * A.include?(A) #=> false
887  */
888 
889 VALUE
891 {
892  VALUE p;
893 
894  Check_Type(mod2, T_MODULE);
895  for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
896  if (BUILTIN_TYPE(p) == T_ICLASS) {
897  if (RBASIC(p)->klass == mod2) return Qtrue;
898  }
899  }
900  return Qfalse;
901 }
902 
903 /*
904  * call-seq:
905  * mod.ancestors -> array
906  *
907  * Returns a list of modules included in <i>mod</i> (including
908  * <i>mod</i> itself).
909  *
910  * module Mod
911  * include Math
912  * include Comparable
913  * end
914  *
915  * Mod.ancestors #=> [Mod, Comparable, Math]
916  * Math.ancestors #=> [Math]
917  */
918 
919 VALUE
921 {
922  VALUE p, ary = rb_ary_new();
923 
924  for (p = mod; p; p = RCLASS_SUPER(p)) {
925  if (FL_TEST(p, FL_SINGLETON))
926  continue;
927  if (BUILTIN_TYPE(p) == T_ICLASS) {
928  rb_ary_push(ary, RBASIC(p)->klass);
929  }
930  else if (p == RCLASS_ORIGIN(p)) {
931  rb_ary_push(ary, p);
932  }
933  }
934  return ary;
935 }
936 
937 #define VISI(x) ((x)&NOEX_MASK)
938 #define VISI_CHECK(x,f) (VISI(x) == (f))
939 
940 static int
941 ins_methods_push(ID name, long type, VALUE ary, long visi)
942 {
943  if (type == -1) return ST_CONTINUE;
944 
945  switch (visi) {
946  case NOEX_PRIVATE:
947  case NOEX_PROTECTED:
948  case NOEX_PUBLIC:
949  visi = (type == visi);
950  break;
951  default:
952  visi = (type != NOEX_PRIVATE);
953  break;
954  }
955  if (visi) {
956  rb_ary_push(ary, ID2SYM(name));
957  }
958  return ST_CONTINUE;
959 }
960 
961 static int
963 {
964  return ins_methods_push((ID)name, (long)type, (VALUE)ary, -1); /* everything but private */
965 }
966 
967 static int
969 {
970  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PROTECTED);
971 }
972 
973 static int
975 {
976  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PRIVATE);
977 }
978 
979 static int
981 {
982  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PUBLIC);
983 }
984 
985 static int
987 {
988  const rb_method_entry_t *me = (const rb_method_entry_t *)value;
989  st_table *list = (st_table *)data;
990  long type;
991 
992  if (!st_lookup(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(list, key, type);
1000  }
1001  return ST_CONTINUE;
1002 }
1003 
1004 static VALUE
1006 {
1007  VALUE ary;
1008  int recur, prepended = 0;
1009  st_table *list;
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  list = st_init_numtable();
1026  for (; mod; mod = RCLASS_SUPER(mod)) {
1028  if (BUILTIN_TYPE(mod) == T_ICLASS && !prepended) continue;
1029  if (obj && FL_TEST(mod, FL_SINGLETON)) continue;
1030  if (!recur) break;
1031  }
1032  ary = rb_ary_new();
1033  st_foreach(list, func, ary);
1034  st_free_table(list);
1035 
1036  return ary;
1037 }
1038 
1039 /*
1040  * call-seq:
1041  * mod.instance_methods(include_super=true) -> array
1042  *
1043  * Returns an array containing the names of the public and protected instance
1044  * methods in the receiver. For a module, these are the public and protected methods;
1045  * for a class, they are the instance (not singleton) methods. With no
1046  * argument, or with an argument that is <code>false</code>, the
1047  * instance methods in <i>mod</i> are returned, otherwise the methods
1048  * in <i>mod</i> and <i>mod</i>'s superclasses are returned.
1049  *
1050  * module A
1051  * def method1() end
1052  * end
1053  * class B
1054  * def method2() end
1055  * end
1056  * class C < B
1057  * def method3() end
1058  * end
1059  *
1060  * A.instance_methods #=> [:method1]
1061  * B.instance_methods(false) #=> [:method2]
1062  * C.instance_methods(false) #=> [:method3]
1063  * C.instance_methods(true).length #=> 43
1064  */
1065 
1066 VALUE
1068 {
1069  return class_instance_method_list(argc, argv, mod, 0, ins_methods_i);
1070 }
1071 
1072 /*
1073  * call-seq:
1074  * mod.protected_instance_methods(include_super=true) -> array
1075  *
1076  * Returns a list of the protected instance methods defined in
1077  * <i>mod</i>. If the optional parameter is not <code>false</code>, the
1078  * methods of any ancestors are included.
1079  */
1080 
1081 VALUE
1083 {
1084  return class_instance_method_list(argc, argv, mod, 0, ins_methods_prot_i);
1085 }
1086 
1087 /*
1088  * call-seq:
1089  * mod.private_instance_methods(include_super=true) -> array
1090  *
1091  * Returns a list of the private instance methods defined in
1092  * <i>mod</i>. If the optional parameter is not <code>false</code>, the
1093  * methods of any ancestors are included.
1094  *
1095  * module Mod
1096  * def method1() end
1097  * private :method1
1098  * def method2() end
1099  * end
1100  * Mod.instance_methods #=> [:method2]
1101  * Mod.private_instance_methods #=> [:method1]
1102  */
1103 
1104 VALUE
1106 {
1107  return class_instance_method_list(argc, argv, mod, 0, ins_methods_priv_i);
1108 }
1109 
1110 /*
1111  * call-seq:
1112  * mod.public_instance_methods(include_super=true) -> array
1113  *
1114  * Returns a list of the public instance methods defined in <i>mod</i>.
1115  * If the optional parameter is not <code>false</code>, the methods of
1116  * any ancestors are included.
1117  */
1118 
1119 VALUE
1121 {
1122  return class_instance_method_list(argc, argv, mod, 0, ins_methods_pub_i);
1123 }
1124 
1125 /*
1126  * call-seq:
1127  * obj.methods(all=true) -> array
1128  *
1129  * Returns a list of the names of public and protected methods of
1130  * <i>obj</i>. This will include all the methods accessible in
1131  * <i>obj</i>'s ancestors.
1132  * If the <i>all</i> parameter is set to <code>false</code>, only those methods
1133  * in the receiver will be listed.
1134  *
1135  * class Klass
1136  * def klass_method()
1137  * end
1138  * end
1139  * k = Klass.new
1140  * k.methods[0..9] #=> [:klass_method, :nil?, :===,
1141  * # :==~, :!, :eql?
1142  * # :hash, :<=>, :class, :singleton_class]
1143  * k.methods.length #=> 57
1144  */
1145 
1146 VALUE
1147 rb_obj_methods(int argc, VALUE *argv, VALUE obj)
1148 {
1149  retry:
1150  if (argc == 0) {
1151  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_i);
1152  }
1153  else {
1154  VALUE recur;
1155 
1156  rb_scan_args(argc, argv, "1", &recur);
1157  if (RTEST(recur)) {
1158  argc = 0;
1159  goto retry;
1160  }
1161  return rb_obj_singleton_methods(argc, argv, obj);
1162  }
1163 }
1164 
1165 /*
1166  * call-seq:
1167  * obj.protected_methods(all=true) -> array
1168  *
1169  * Returns the list of protected methods accessible to <i>obj</i>. If
1170  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1171  * in the receiver will be listed.
1172  */
1173 
1174 VALUE
1175 rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj)
1176 {
1177  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_prot_i);
1178 }
1179 
1180 /*
1181  * call-seq:
1182  * obj.private_methods(all=true) -> array
1183  *
1184  * Returns the list of private methods accessible to <i>obj</i>. If
1185  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1186  * in the receiver will be listed.
1187  */
1188 
1189 VALUE
1190 rb_obj_private_methods(int argc, VALUE *argv, VALUE obj)
1191 {
1192  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_priv_i);
1193 }
1194 
1195 /*
1196  * call-seq:
1197  * obj.public_methods(all=true) -> array
1198  *
1199  * Returns the list of public methods accessible to <i>obj</i>. If
1200  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1201  * in the receiver will be listed.
1202  */
1203 
1204 VALUE
1205 rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
1206 {
1207  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_pub_i);
1208 }
1209 
1210 /*
1211  * call-seq:
1212  * obj.singleton_methods(all=true) -> array
1213  *
1214  * Returns an array of the names of singleton methods for <i>obj</i>.
1215  * If the optional <i>all</i> parameter is true, the list will include
1216  * methods in modules included in <i>obj</i>.
1217  * Only public and protected singleton methods are returned.
1218  *
1219  * module Other
1220  * def three() end
1221  * end
1222  *
1223  * class Single
1224  * def Single.four() end
1225  * end
1226  *
1227  * a = Single.new
1228  *
1229  * def a.one()
1230  * end
1231  *
1232  * class << a
1233  * include Other
1234  * def two()
1235  * end
1236  * end
1237  *
1238  * Single.singleton_methods #=> [:four]
1239  * a.singleton_methods(false) #=> [:two, :one]
1240  * a.singleton_methods #=> [:two, :one, :three]
1241  */
1242 
1243 VALUE
1244 rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
1245 {
1246  VALUE recur, ary, klass;
1247  st_table *list;
1248 
1249  if (argc == 0) {
1250  recur = Qtrue;
1251  }
1252  else {
1253  rb_scan_args(argc, argv, "01", &recur);
1254  }
1255  klass = CLASS_OF(obj);
1256  list = st_init_numtable();
1257  if (klass && FL_TEST(klass, FL_SINGLETON)) {
1258  if (RCLASS_M_TBL(klass))
1260  klass = RCLASS_SUPER(klass);
1261  }
1262  if (RTEST(recur)) {
1263  while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
1264  if (RCLASS_M_TBL(klass))
1266  klass = RCLASS_SUPER(klass);
1267  }
1268  }
1269  ary = rb_ary_new();
1270  st_foreach(list, ins_methods_i, ary);
1271  st_free_table(list);
1272 
1273  return ary;
1274 }
1275 
1333 void
1335 {
1336  rb_add_method_cfunc(klass, mid, func, argc, NOEX_PUBLIC);
1337 }
1338 
1339 void
1340 rb_define_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
1341 {
1342  rb_add_method_cfunc(klass, rb_intern(name), func, argc, NOEX_PUBLIC);
1343 }
1344 
1345 void
1346 rb_define_protected_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
1347 {
1348  rb_add_method_cfunc(klass, rb_intern(name), func, argc, NOEX_PROTECTED);
1349 }
1350 
1351 void
1352 rb_define_private_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
1353 {
1354  rb_add_method_cfunc(klass, rb_intern(name), func, argc, NOEX_PRIVATE);
1355 }
1356 
1357 void
1358 rb_undef_method(VALUE klass, const char *name)
1359 {
1361 }
1362 
1371 #define SPECIAL_SINGLETON(x,c) do {\
1372  if (obj == (x)) {\
1373  return (c);\
1374  }\
1375 } while (0)
1376 
1377 static inline VALUE
1379 {
1383  return Qnil;
1384 }
1385 
1386 VALUE
1388 {
1389  return special_singleton_class_of(obj);
1390 }
1391 
1401 static VALUE
1403 {
1404  VALUE klass;
1405 
1406  if (FIXNUM_P(obj) || FLONUM_P(obj) || SYMBOL_P(obj)) {
1407  rb_raise(rb_eTypeError, "can't define singleton");
1408  }
1409  if (SPECIAL_CONST_P(obj)) {
1410  klass = special_singleton_class_of(obj);
1411  if (NIL_P(klass))
1412  rb_bug("unknown immediate %p", (void *)obj);
1413  return klass;
1414  }
1415  else {
1416  enum ruby_value_type type = BUILTIN_TYPE(obj);
1417  if (type == T_FLOAT || type == T_BIGNUM) {
1418  rb_raise(rb_eTypeError, "can't define singleton");
1419  }
1420  }
1421 
1422  if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) &&
1423  rb_ivar_get(RBASIC(obj)->klass, id_attached) == obj) {
1424  klass = RBASIC(obj)->klass;
1425  }
1426  else {
1427  klass = rb_make_metaclass(obj, RBASIC(obj)->klass);
1428  }
1429 
1430  if (OBJ_TAINTED(obj)) {
1431  OBJ_TAINT(klass);
1432  }
1433  else {
1434  FL_UNSET(klass, FL_TAINT);
1435  }
1436  if (OBJ_UNTRUSTED(obj)) {
1437  OBJ_UNTRUST(klass);
1438  }
1439  else {
1440  FL_UNSET(klass, FL_UNTRUSTED);
1441  }
1442  if (OBJ_FROZEN(obj)) OBJ_FREEZE(klass);
1443 
1444  return klass;
1445 }
1446 
1447 
1465 VALUE
1467 {
1468  VALUE klass = singleton_class_of(obj);
1469 
1470  /* ensures an exposed class belongs to its own eigenclass */
1471  if (RB_TYPE_P(obj, T_CLASS)) (void)ENSURE_EIGENCLASS(klass);
1472 
1473  return klass;
1474 }
1475 
1492 void
1493 rb_define_singleton_method(VALUE obj, const char *name, VALUE (*func)(ANYARGS), int argc)
1494 {
1495  rb_define_method(singleton_class_of(obj), name, func, argc);
1496 }
1497 
1498 
1499 
1507 void
1508 rb_define_module_function(VALUE module, const char *name, VALUE (*func)(ANYARGS), int argc)
1509 {
1510  rb_define_private_method(module, name, func, argc);
1511  rb_define_singleton_method(module, name, func, argc);
1512 }
1513 
1514 
1521 void
1522 rb_define_global_function(const char *name, VALUE (*func)(ANYARGS), int argc)
1523 {
1525 }
1526 
1527 
1534 void
1535 rb_define_alias(VALUE klass, const char *name1, const char *name2)
1536 {
1537  rb_alias(klass, rb_intern(name1), rb_intern(name2));
1538 }
1539 
1547 void
1548 rb_define_attr(VALUE klass, const char *name, int read, int write)
1549 {
1550  rb_attr(klass, rb_intern(name), read, write, FALSE);
1551 }
1552 
1553 int
1555 {
1556  const rb_method_entry_t *me = rb_method_entry(CLASS_OF(obj), rb_intern("to_s"), 0);
1557  if (me && me->def && me->def->type == VM_METHOD_TYPE_CFUNC &&
1558  me->def->body.cfunc.func == rb_any_to_s)
1559  return 1;
1560  return 0;
1561 }
1562 
1563 #include <stdarg.h>
1564 
1565 int
1566 rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
1567 {
1568  int i;
1569  const char *p = fmt;
1570  VALUE *var;
1571  va_list vargs;
1572  int f_var = 0, f_hash = 0, f_block = 0;
1573  int n_lead = 0, n_opt = 0, n_trail = 0, n_mand;
1574  int argi = 0;
1575  VALUE hash = Qnil;
1576 
1577  if (ISDIGIT(*p)) {
1578  n_lead = *p - '0';
1579  p++;
1580  if (ISDIGIT(*p)) {
1581  n_opt = *p - '0';
1582  p++;
1583  if (ISDIGIT(*p)) {
1584  n_trail = *p - '0';
1585  p++;
1586  goto block_arg;
1587  }
1588  }
1589  }
1590  if (*p == '*') {
1591  f_var = 1;
1592  p++;
1593  if (ISDIGIT(*p)) {
1594  n_trail = *p - '0';
1595  p++;
1596  }
1597  }
1598  block_arg:
1599  if (*p == ':') {
1600  f_hash = 1;
1601  p++;
1602  }
1603  if (*p == '&') {
1604  f_block = 1;
1605  p++;
1606  }
1607  if (*p != '\0') {
1608  rb_fatal("bad scan arg format: %s", fmt);
1609  }
1610  n_mand = n_lead + n_trail;
1611 
1612  if (argc < n_mand)
1613  goto argc_error;
1614 
1615  va_start(vargs, fmt);
1616 
1617  /* capture an option hash - phase 1: pop */
1618  if (f_hash && n_mand < argc) {
1619  VALUE last = argv[argc - 1];
1620 
1621  if (NIL_P(last)) {
1622  /* nil is taken as an empty option hash only if it is not
1623  ambiguous; i.e. '*' is not specified and arguments are
1624  given more than sufficient */
1625  if (!f_var && n_mand + n_opt < argc)
1626  argc--;
1627  }
1628  else {
1629  hash = rb_check_hash_type(last);
1630  if (!NIL_P(hash))
1631  argc--;
1632  }
1633  }
1634  /* capture leading mandatory arguments */
1635  for (i = n_lead; i-- > 0; ) {
1636  var = va_arg(vargs, VALUE *);
1637  if (var) *var = argv[argi];
1638  argi++;
1639  }
1640  /* capture optional arguments */
1641  for (i = n_opt; i-- > 0; ) {
1642  var = va_arg(vargs, VALUE *);
1643  if (argi < argc - n_trail) {
1644  if (var) *var = argv[argi];
1645  argi++;
1646  }
1647  else {
1648  if (var) *var = Qnil;
1649  }
1650  }
1651  /* capture variable length arguments */
1652  if (f_var) {
1653  int n_var = argc - argi - n_trail;
1654 
1655  var = va_arg(vargs, VALUE *);
1656  if (0 < n_var) {
1657  if (var) *var = rb_ary_new4(n_var, &argv[argi]);
1658  argi += n_var;
1659  }
1660  else {
1661  if (var) *var = rb_ary_new();
1662  }
1663  }
1664  /* capture trailing mandatory arguments */
1665  for (i = n_trail; i-- > 0; ) {
1666  var = va_arg(vargs, VALUE *);
1667  if (var) *var = argv[argi];
1668  argi++;
1669  }
1670  /* capture an option hash - phase 2: assignment */
1671  if (f_hash) {
1672  var = va_arg(vargs, VALUE *);
1673  if (var) *var = hash;
1674  }
1675  /* capture iterator block */
1676  if (f_block) {
1677  var = va_arg(vargs, VALUE *);
1678  if (rb_block_given_p()) {
1679  *var = rb_block_proc();
1680  }
1681  else {
1682  *var = Qnil;
1683  }
1684  }
1685  va_end(vargs);
1686 
1687  if (argi < argc) {
1688  argc_error:
1689  rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt);
1690  }
1691 
1692  return argc;
1693 }
1694 
VALUE data
Definition: tcltklib.c:3368
static VALUE make_metaclass(VALUE klass)
Creates a metaclass of klass.
Definition: class.c:340
#define RB_TYPE_P(obj, type)
VALUE rb_const_get_at(VALUE, ID)
Definition: variable.c:1877
#define ALLOC(type)
volatile VALUE tmp
Definition: tcltklib.c:10209
#define UNDEFINED_METHOD_ENTRY_P(me)
Definition: method.h:108
VALUE rb_define_module_id_under(VALUE outer, ID id)
Definition: class.c:643
volatile VALUE ary
Definition: tcltklib.c:9713
#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:1016
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:890
VALUE rb_any_to_s(VALUE)
Definition: object.c:384
void rb_bug(const char *fmt,...)
Definition: error.c:290
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:941
static ID id_attached
Definition: class.c:35
Definition: constant.h:19
const char * rb_obj_classname(VALUE)
Definition: variable.c:391
VALUE rb_obj_private_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1190
VALUE rb_id2str(ID id)
Definition: ripper.c:16007
Win32OLEIDispatch * p
Definition: win32ole.c:786
#define VISI(x)
Definition: class.c:937
#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:624
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1493
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:1105
#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:568
#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:1871
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:5655
struct rb_method_entry_struct * orig_me
Definition: method.h:90
VALUE rb_mod_ancestors(VALUE mod)
Definition: class.c:920
VALUE rb_refinement_module_get_refined_class(VALUE module)
Definition: eval.c:1129
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1352
#define RCLASS_ORIGIN(c)
VALUE rb_eTypeError
Definition: error.c:511
#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:241
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:4068
VALUE var
Definition: tcltklib.c:5517
void Init_class_hierarchy(void)
Definition: class.c:401
#define xfree
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:774
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:545
static int ins_methods_priv_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:974
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1780
return Qtrue
Definition: tcltklib.c:9610
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:695
r
Definition: bigdecimal.c:1196
#define FL_UNTRUSTED
void rb_define_protected_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1346
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1522
#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:1280
void rb_undef_method(VALUE klass, const char *name)
Definition: class.c:1358
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1111
const char * fmt
Definition: tcltklib.c:841
#define RCLASS_EXT(c)
void rb_name_error(ID id, const char *fmt,...)
Definition: error.c:899
Definition: ripper.y:240
char * name2
Definition: tcltklib.c:4206
void rb_prepend_module(VALUE klass, VALUE module)
Definition: class.c:801
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:1466
VALUE hash
Definition: tkutil.c:267
rb_method_cfunc_t cfunc
Definition: method.h:81
VALUE rb_block_proc(void)
Definition: proc.c:479
VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
Definition: class.c:473
BDIGIT m
Definition: bigdecimal.c:5085
#define FIXNUM_P(f)
return Qfalse
Definition: tcltklib.c:6779
NODE * cref_stack
Definition: vm_core.h:304
int rb_block_given_p(void)
Definition: eval.c:672
#define Qnil
Definition: tcltklib.c:1896
VALUE rb_special_singleton_class(VALUE obj)
Definition: class.c:1387
#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:388
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:3023
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:499
static VALUE VALUE obj
Definition: tcltklib.c:3158
static VALUE special_singleton_class_of(VALUE obj)
Definition: class.c:1378
void rb_clear_cache(void)
Definition: vm_method.c:46
VALUE rb_define_module_id(ID id)
Definition: class.c:606
#define METACLASS_OF(k)
Definition: class.c:301
#define ANYARGS
#define META_CLASS_OF_CLASS_CLASS_P(k)
whether k is a meta^(n)-class of Class class
Definition: class.c:308
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:1175
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:551
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:1554
VALUE * argv
Definition: tcltklib.c:1971
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
Definition: class.c:1535
#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:1508
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
Definition: st.c:1000
static int add_refined_method_entry_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:717
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
volatile VALUE value
Definition: tcltklib.c:9442
va_list vargs
Definition: regerror.c:267
int rb_const_defined(VALUE, ID)
Definition: variable.c:2098
VALUE rb_include_class_new(VALUE module, VALUE super)
Definition: class.c:663
void rb_fatal(const char *fmt,...)
Definition: error.c:1834
char * name1
Definition: tcltklib.c:4205
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:402
#define CONST_ID(var, str)
void rb_gc_register_mark_object(VALUE)
Definition: gc.c:2980
VP_EXPORT void
Definition: bigdecimal.c:5083
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1566
void rb_attr(VALUE, ID, int, int, int)
Definition: vm_method.c:791
static int ins_methods_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:962
void rb_const_set(VALUE, ID, VALUE)
Definition: variable.c:2136
#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:724
VALUE rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1205
static int ins_methods_pub_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:980
int argc
Definition: tcltklib.c:1970
void rb_alias(VALUE, ID, ID)
Definition: vm_method.c:1175
int rb_const_defined_at(VALUE, ID)
Definition: variable.c:2104
VALUE rb_make_metaclass(VALUE obj, VALUE unused)
Definition: class.c:430
VpDivd * c
Definition: bigdecimal.c:1205
VALUE rb_class_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1067
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:637
#define recur(fmt)
const char * rb_class2name(VALUE)
Definition: variable.c:384
VALUE rb_obj_init_copy(VALUE, VALUE)
Definition: object.c:354
VALUE rb_class_protected_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1082
#define NEWOBJ_OF(obj, type, klass, flags)
void rb_define_method_id(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1334
VALUE rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1120
void rb_singleton_class_attached(VALUE klass, VALUE obj)
Attach a object to a singleton class.
Definition: class.c:289
#define SYMBOL_P(x)
#define FL_SINGLETON
VALUE rb_module_new(void)
Definition: class.c:596
#define Qundef
#define T_CLASS
#define ENSURE_EIGENCLASS(klass)
ensures klass belongs to its own eigenclass.
Definition: class.c:326
VALUE rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1244
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:1548
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:373
#define RBASIC(obj)
klass
Definition: tcltklib.c:3504
static int method_entry_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:986
struct rb_encoding_entry * list
Definition: encoding.c:50
VALUE rb_obj_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1147
void rb_add_refined_method_entry(VALUE refined_class, ID mid)
Definition: vm_method.c:210
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:968
void rb_set_class_path_string(VALUE, VALUE, VALUE)
Definition: variable.c:280
#define OBJ_UNTRUST(x)
static int move_refined_method(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:774
#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:16068
VALUE rb_mod_included_modules(VALUE mod)
Definition: class.c:854
#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:452
unsigned long VALUE
Definition: ripper.y:104
#define SPECIAL_SINGLETON(x, c)
Definition: class.c:1371
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:464
st_table * st_copy(st_table *)
Definition: st.c:658
#define RMODULE_IS_REFINEMENT
#define SPECIAL_CONST_P(x)
#define OBJ_TAINT(x)
VALUE rb_define_module(const char *name)
Definition: class.c:617
RUBY_EXTERN VALUE rb_cFalseClass
Definition: ripper.y:1434
void rb_name_class(VALUE, ID)
Definition: variable.c:372
#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:1402
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:1884
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:1340
int retry
Definition: tcltklib.c:10151
void rb_warn(const char *fmt,...)
Definition: error.c:216
VALUE rb_class_boot(VALUE super)
A utility function that wraps class_alloc.
Definition: class.c:76
VALUE rb_eArgError
Definition: error.c:512
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:247
#define RMODULE_INCLUDED_INTO_REFINEMENT