Ruby  2.1.3p242(2014-09-19revision47630)
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 int rb_vm_add_root_module(ID id, VALUE module);
35 
36 
37 #define id_attached id__attached__
38 
39 void
41 {
42  rb_subclass_entry_t *entry, *head;
43 
44  if (super && super != Qundef) {
45  entry = xmalloc(sizeof(*entry));
46  entry->klass = klass;
47  entry->next = NULL;
48 
49  head = RCLASS_EXT(super)->subclasses;
50  if (head) {
51  entry->next = head;
52  RCLASS_EXT(head->klass)->parent_subclasses = &entry->next;
53  }
54 
55  RCLASS_EXT(super)->subclasses = entry;
56  RCLASS_EXT(klass)->parent_subclasses = &RCLASS_EXT(super)->subclasses;
57  }
58 }
59 
60 static void
62 {
63  rb_subclass_entry_t *entry, *head;
64 
65  entry = xmalloc(sizeof(*entry));
66  entry->klass = iclass;
67  entry->next = NULL;
68 
69  head = RCLASS_EXT(module)->subclasses;
70  if (head) {
71  entry->next = head;
72  RCLASS_EXT(head->klass)->module_subclasses = &entry->next;
73  }
74 
75  RCLASS_EXT(module)->subclasses = entry;
76  RCLASS_EXT(iclass)->module_subclasses = &RCLASS_EXT(module)->subclasses;
77 }
78 
79 void
81 {
82  rb_subclass_entry_t *entry;
83 
84  if (RCLASS_EXT(klass)->parent_subclasses) {
85  entry = *RCLASS_EXT(klass)->parent_subclasses;
86 
87  *RCLASS_EXT(klass)->parent_subclasses = entry->next;
88  if (entry->next) {
89  RCLASS_EXT(entry->next->klass)->parent_subclasses = RCLASS_EXT(klass)->parent_subclasses;
90  }
91  xfree(entry);
92  }
93 
94  RCLASS_EXT(klass)->parent_subclasses = NULL;
95 }
96 
97 void
99 {
100  rb_subclass_entry_t *entry;
101 
102  if (RCLASS_EXT(klass)->module_subclasses) {
103  entry = *RCLASS_EXT(klass)->module_subclasses;
104  *RCLASS_EXT(klass)->module_subclasses = entry->next;
105 
106  if (entry->next) {
107  RCLASS_EXT(entry->next->klass)->module_subclasses = RCLASS_EXT(klass)->module_subclasses;
108  }
109 
110  xfree(entry);
111  }
112 
113  RCLASS_EXT(klass)->module_subclasses = NULL;
114 }
115 
116 void
118 {
119  rb_subclass_entry_t *cur = RCLASS_EXT(klass)->subclasses;
120 
121  /* do not be tempted to simplify this loop into a for loop, the order of
122  operations is important here if `f` modifies the linked list */
123  while (cur) {
124  VALUE curklass = cur->klass;
125  cur = cur->next;
126  f(curklass);
127  }
128 }
129 
130 void
132 {
134 }
135 
136 void
138 {
140 }
141 
154 static VALUE
155 class_alloc(VALUE flags, VALUE klass)
156 {
157  NEWOBJ_OF(obj, struct RClass, klass, (flags & T_MASK) | (RGENGC_WB_PROTECTED_CLASS ? FL_WB_PROTECTED : 0));
158  obj->ptr = ALLOC(rb_classext_t);
159  RCLASS_IV_TBL(obj) = 0;
160  RCLASS_CONST_TBL(obj) = 0;
161  RCLASS_M_TBL_WRAPPER(obj) = 0;
162  RCLASS_SET_SUPER((VALUE)obj, 0);
163  RCLASS_ORIGIN(obj) = (VALUE)obj;
164  RCLASS_IV_INDEX_TBL(obj) = 0;
165 
166  RCLASS_EXT(obj)->subclasses = NULL;
167  RCLASS_EXT(obj)->parent_subclasses = NULL;
168  RCLASS_EXT(obj)->module_subclasses = NULL;
170 
171  RCLASS_REFINED_CLASS(obj) = Qnil;
172  RCLASS_EXT(obj)->allocator = 0;
173  return (VALUE)obj;
174 }
175 
176 
186 VALUE
188 {
190 
191  RCLASS_SET_SUPER(klass, super);
192  RCLASS_M_TBL_INIT(klass);
193 
194  OBJ_INFECT(klass, super);
195  return (VALUE)klass;
196 }
197 
198 
205 void
207 {
208  if (!RB_TYPE_P(super, T_CLASS)) {
209  rb_raise(rb_eTypeError, "superclass must be a Class (%s given)",
210  rb_obj_classname(super));
211  }
212  if (RBASIC(super)->flags & FL_SINGLETON) {
213  rb_raise(rb_eTypeError, "can't make subclass of singleton class");
214  }
215  if (super == rb_cClass) {
216  rb_raise(rb_eTypeError, "can't make subclass of Class");
217  }
218 }
219 
220 
227 VALUE
229 {
230  Check_Type(super, T_CLASS);
231  rb_check_inheritable(super);
232  return rb_class_boot(super);
233 }
234 
235 static void
236 rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr)
237 {
238  NODE *new_node;
239  while (node) {
240  if (node->nd_clss == old_klass) {
241  new_node = NEW_CREF(new_klass);
242  RB_OBJ_WRITE(new_node, &new_node->nd_next, node->nd_next);
243  *new_cref_ptr = new_node;
244  return;
245  }
246  new_node = NEW_CREF(node->nd_clss);
247  node = node->nd_next;
248  *new_cref_ptr = new_node;
249  new_cref_ptr = &new_node->nd_next;
250  }
251  *new_cref_ptr = NULL;
252 }
253 
254 static void
255 clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
256 {
257  VALUE newiseqval;
258  if (me->def && me->def->type == VM_METHOD_TYPE_ISEQ) {
259  rb_iseq_t *iseq;
260  NODE *new_cref;
261  newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass);
262  GetISeqPtr(newiseqval, iseq);
263  rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass, &new_cref);
264  RB_OBJ_WRITE(iseq->self, &iseq->cref_stack, new_cref);
265  rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
266  RB_GC_GUARD(newiseqval);
267  }
268  else {
269  rb_method_entry_set(klass, mid, me, me->flag);
270  }
271 }
272 
273 static int
275 {
276  clone_method((VALUE)data, (ID)key, (const rb_method_entry_t *)value);
277  return ST_CONTINUE;
278 }
279 
283 };
284 
285 static int
287 {
289  MEMCPY(nce, ce, rb_const_entry_t, 1);
290  RB_OBJ_WRITTEN(arg->klass, Qundef, ce->value);
291  RB_OBJ_WRITTEN(arg->klass, Qundef, ce->file);
292 
293  st_insert(arg->tbl, key, (st_data_t)nce);
294  return ST_CONTINUE;
295 }
296 
297 static int
299 {
300  return clone_const((ID)key, (const rb_const_entry_t *)value, (struct clone_const_arg *)data);
301 }
302 
303 static void
305 {
306  if (orig == rb_cBasicObject) {
307  rb_raise(rb_eTypeError, "can't copy the root class");
308  }
309  if (RCLASS_SUPER(clone) != 0 || clone == rb_cBasicObject) {
310  rb_raise(rb_eTypeError, "already initialized class");
311  }
312  if (FL_TEST(orig, FL_SINGLETON)) {
313  rb_raise(rb_eTypeError, "can't copy singleton class");
314  }
315 }
316 
317 /* :nodoc: */
318 VALUE
320 {
321  if (RB_TYPE_P(clone, T_CLASS)) {
322  class_init_copy_check(clone, orig);
323  }
324  if (!OBJ_INIT_COPY(clone, orig)) return clone;
325  if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
327  rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
328  }
329  RCLASS_SET_SUPER(clone, RCLASS_SUPER(orig));
330  RCLASS_EXT(clone)->allocator = RCLASS_EXT(orig)->allocator;
331  if (RCLASS_IV_TBL(clone)) {
333  RCLASS_IV_TBL(clone) = 0;
334  }
335  if (RCLASS_CONST_TBL(clone)) {
337  RCLASS_CONST_TBL(clone) = 0;
338  }
339  if (RCLASS_M_TBL_WRAPPER(clone)) {
341  RCLASS_M_TBL_WRAPPER(clone) = 0;
342  }
343  if (RCLASS_IV_TBL(orig)) {
344  st_data_t id;
345 
346  RCLASS_IV_TBL(clone) = rb_st_copy(clone, RCLASS_IV_TBL(orig));
347  CONST_ID(id, "__tmp_classpath__");
348  st_delete(RCLASS_IV_TBL(clone), &id, 0);
349  CONST_ID(id, "__classpath__");
350  st_delete(RCLASS_IV_TBL(clone), &id, 0);
351  CONST_ID(id, "__classid__");
352  st_delete(RCLASS_IV_TBL(clone), &id, 0);
353  }
354  if (RCLASS_CONST_TBL(orig)) {
355  struct clone_const_arg arg;
356 
358  arg.klass = clone;
359  arg.tbl = RCLASS_CONST_TBL(clone);
361  }
362  if (RCLASS_M_TBL(orig)) {
363  RCLASS_M_TBL_INIT(clone);
365  }
366 
367  return clone;
368 }
369 
370 VALUE
372 {
374 }
375 
376 VALUE
378 {
379  VALUE klass = RBASIC(obj)->klass;
380 
381  if (!FL_TEST(klass, FL_SINGLETON))
382  return klass;
383  else {
384  /* copy singleton(unnamed) class */
385  VALUE clone = class_alloc(RBASIC(klass)->flags, 0);
386 
387  if (BUILTIN_TYPE(obj) == T_CLASS) {
388  RBASIC_SET_CLASS(clone, clone);
389  }
390  else {
392  }
393 
394  RCLASS_SET_SUPER(clone, RCLASS_SUPER(klass));
395  RCLASS_EXT(clone)->allocator = RCLASS_EXT(klass)->allocator;
396  if (RCLASS_IV_TBL(klass)) {
397  RCLASS_IV_TBL(clone) = rb_st_copy(clone, RCLASS_IV_TBL(klass));
398  }
399  if (RCLASS_CONST_TBL(klass)) {
400  struct clone_const_arg arg;
402  arg.klass = clone;
403  arg.tbl = RCLASS_CONST_TBL(clone);
405  }
406  if (attach != Qundef) {
407  rb_singleton_class_attached(clone, attach);
408  }
409  RCLASS_M_TBL_INIT(clone);
411  rb_singleton_class_attached(RBASIC(clone)->klass, clone);
412  FL_SET(clone, FL_SINGLETON);
413 
414  return clone;
415  }
416 }
417 
422 void
424 {
425  if (FL_TEST(klass, FL_SINGLETON)) {
426  if (!RCLASS_IV_TBL(klass)) {
427  RCLASS_IV_TBL(klass) = st_init_numtable();
428  }
430  }
431 }
432 
433 
434 
435 #define METACLASS_OF(k) RBASIC(k)->klass
436 #define SET_METACLASS_OF(k, cls) RBASIC_SET_CLASS(k, cls)
437 
443 #define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k))
444 
450 #define HAVE_METACLASS_P(k) \
451  (FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \
452  rb_ivar_get(METACLASS_OF(k), id_attached) == (k))
453 
461 #define ENSURE_EIGENCLASS(klass) \
462  (HAVE_METACLASS_P(klass) ? METACLASS_OF(klass) : make_metaclass(klass))
463 
464 
474 static inline VALUE
476 {
477  VALUE super;
478  VALUE metaclass = rb_class_boot(Qundef);
479 
480  FL_SET(metaclass, FL_SINGLETON);
481  rb_singleton_class_attached(metaclass, klass);
482 
483  if (META_CLASS_OF_CLASS_CLASS_P(klass)) {
484  SET_METACLASS_OF(klass, metaclass);
485  SET_METACLASS_OF(metaclass, metaclass);
486  }
487  else {
488  VALUE tmp = METACLASS_OF(klass); /* for a meta^(n)-class klass, tmp is meta^(n)-class of Class class */
489  SET_METACLASS_OF(klass, metaclass);
490  SET_METACLASS_OF(metaclass, ENSURE_EIGENCLASS(tmp));
491  }
492 
493  super = RCLASS_SUPER(klass);
494  while (RB_TYPE_P(super, T_ICLASS)) super = RCLASS_SUPER(super);
495  RCLASS_SET_SUPER(metaclass, super ? ENSURE_EIGENCLASS(super) : rb_cClass);
496 
497  OBJ_INFECT(metaclass, RCLASS_SUPER(metaclass));
498 
499  return metaclass;
500 }
501 
508 static inline VALUE
510 {
511  VALUE orig_class = RBASIC(obj)->klass;
512  VALUE klass = rb_class_boot(orig_class);
513 
514  FL_SET(klass, FL_SINGLETON);
515  RBASIC_SET_CLASS(obj, klass);
516  rb_singleton_class_attached(klass, obj);
517 
518  SET_METACLASS_OF(klass, METACLASS_OF(rb_class_real(orig_class)));
519  return klass;
520 }
521 
522 
523 static VALUE
524 boot_defclass(const char *name, VALUE super)
525 {
526  VALUE obj = rb_class_boot(super);
527  ID id = rb_intern(name);
528 
529  rb_name_class(obj, id);
530  rb_const_set((rb_cObject ? rb_cObject : obj), id, obj);
531  return obj;
532 }
533 
534 void
536 {
537  rb_cBasicObject = boot_defclass("BasicObject", 0);
539  rb_cModule = boot_defclass("Module", rb_cObject);
540  rb_cClass = boot_defclass("Class", rb_cModule);
541 
547 }
548 
549 
560 VALUE
562 {
563  if (BUILTIN_TYPE(obj) == T_CLASS) {
564  return make_metaclass(obj);
565  }
566  else {
567  return make_singleton_class(obj);
568  }
569 }
570 
571 
582 VALUE
584 {
585  VALUE klass;
586 
587  if (!super) super = rb_cObject;
588  klass = rb_class_new(super);
589  rb_make_metaclass(klass, RBASIC(super)->klass);
590 
591  return klass;
592 }
593 
594 
603 VALUE
605 {
606  ID inherited;
607  if (!super) super = rb_cObject;
608  CONST_ID(inherited, "inherited");
609  return rb_funcall(super, inherited, 1, klass);
610 }
611 
612 
613 
629 VALUE
630 rb_define_class(const char *name, VALUE super)
631 {
632  VALUE klass;
633  ID id;
634 
635  id = rb_intern(name);
636  if (rb_const_defined(rb_cObject, id)) {
637  klass = rb_const_get(rb_cObject, id);
638  if (!RB_TYPE_P(klass, T_CLASS)) {
639  rb_raise(rb_eTypeError, "%s is not a class", name);
640  }
641  if (rb_class_real(RCLASS_SUPER(klass)) != super) {
642  rb_raise(rb_eTypeError, "superclass mismatch for class %s", name);
643  }
644  return klass;
645  }
646  if (!super) {
647  rb_warn("no super class for `%s', Object assumed", name);
648  }
649  klass = rb_define_class_id(id, super);
650  rb_vm_add_root_module(id, klass);
651  rb_name_class(klass, id);
652  rb_const_set(rb_cObject, id, klass);
653  rb_class_inherited(super, klass);
654 
655  return klass;
656 }
657 
658 
675 VALUE
676 rb_define_class_under(VALUE outer, const char *name, VALUE super)
677 {
678  return rb_define_class_id_under(outer, rb_intern(name), super);
679 }
680 
681 
698 VALUE
700 {
701  VALUE klass;
702 
703  if (rb_const_defined_at(outer, id)) {
704  klass = rb_const_get_at(outer, id);
705  if (!RB_TYPE_P(klass, T_CLASS)) {
706  rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
707  }
708  if (rb_class_real(RCLASS_SUPER(klass)) != super) {
709  rb_name_error(id, "%s is already defined", rb_id2name(id));
710  }
711  return klass;
712  }
713  if (!super) {
714  rb_warn("no super class for `%s::%s', Object assumed",
715  rb_class2name(outer), rb_id2name(id));
716  }
717  klass = rb_define_class_id(id, super);
718  rb_set_class_path_string(klass, outer, rb_id2str(id));
719  rb_const_set(outer, id, klass);
720  rb_class_inherited(super, klass);
722 
723  return klass;
724 }
725 
726 VALUE
728 {
730  RCLASS_M_TBL_INIT(mdl);
731  return (VALUE)mdl;
732 }
733 
734 VALUE
736 {
737  VALUE mdl;
738 
739  mdl = rb_module_new();
740  rb_name_class(mdl, id);
741 
742  return mdl;
743 }
744 
745 VALUE
746 rb_define_module(const char *name)
747 {
748  VALUE module;
749  ID id;
750 
751  id = rb_intern(name);
752  if (rb_const_defined(rb_cObject, id)) {
753  module = rb_const_get(rb_cObject, id);
754  if (RB_TYPE_P(module, T_MODULE))
755  return module;
756  rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module));
757  }
758  module = rb_define_module_id(id);
759  rb_vm_add_root_module(id, module);
760  rb_const_set(rb_cObject, id, module);
761 
762  return module;
763 }
764 
765 VALUE
766 rb_define_module_under(VALUE outer, const char *name)
767 {
768  return rb_define_module_id_under(outer, rb_intern(name));
769 }
770 
771 VALUE
773 {
774  VALUE module;
775 
776  if (rb_const_defined_at(outer, id)) {
777  module = rb_const_get_at(outer, id);
778  if (RB_TYPE_P(module, T_MODULE))
779  return module;
780  rb_raise(rb_eTypeError, "%s::%s is not a module",
781  rb_class2name(outer), rb_obj_classname(module));
782  }
783  module = rb_define_module_id(id);
784  rb_const_set(outer, id, module);
785  rb_set_class_path_string(module, outer, rb_id2str(id));
787 
788  return module;
789 }
790 
791 VALUE
793 {
795 
796  if (BUILTIN_TYPE(module) == T_ICLASS) {
797  module = RBASIC(module)->klass;
798  }
799  if (!RCLASS_IV_TBL(module)) {
800  RCLASS_IV_TBL(module) = st_init_numtable();
801  }
802  if (!RCLASS_CONST_TBL(module)) {
804  }
805  RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
806  RCLASS_CONST_TBL(klass) = RCLASS_CONST_TBL(module);
807 
810 
811  RCLASS_SET_SUPER(klass, super);
812  if (RB_TYPE_P(module, T_ICLASS)) {
813  RBASIC_SET_CLASS(klass, RBASIC(module)->klass);
814  }
815  else {
816  RBASIC_SET_CLASS(klass, module);
817  }
818  OBJ_INFECT(klass, module);
819  OBJ_INFECT(klass, super);
820 
821  return (VALUE)klass;
822 }
823 
824 static int include_modules_at(const VALUE klass, VALUE c, VALUE module);
825 
826 void
828 {
829  int changed = 0;
830 
831  rb_frozen_class_p(klass);
832 
833  if (!RB_TYPE_P(module, T_MODULE)) {
834  Check_Type(module, T_MODULE);
835  }
836 
837  OBJ_INFECT(klass, module);
838 
839  changed = include_modules_at(klass, RCLASS_ORIGIN(klass), module);
840  if (changed < 0)
841  rb_raise(rb_eArgError, "cyclic include detected");
842 }
843 
844 static int
846 {
847  rb_add_refined_method_entry((VALUE) data, (ID) key);
848  return ST_CONTINUE;
849 }
850 
851 static int
852 include_modules_at(const VALUE klass, VALUE c, VALUE module)
853 {
854  VALUE p, iclass;
855  int method_changed = 0, constant_changed = 0;
856  const st_table *const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass));
857 
858  while (module) {
859  int superclass_seen = FALSE;
860 
861  if (RCLASS_ORIGIN(module) != module)
862  goto skip;
863  if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module))
864  return -1;
865  /* ignore if the module included already in superclasses */
866  for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
867  switch (BUILTIN_TYPE(p)) {
868  case T_ICLASS:
869  if (RCLASS_M_TBL_WRAPPER(p) == RCLASS_M_TBL_WRAPPER(module)) {
870  if (!superclass_seen) {
871  c = p; /* move insertion point */
872  }
873  goto skip;
874  }
875  break;
876  case T_CLASS:
877  superclass_seen = TRUE;
878  break;
879  }
880  }
881  iclass = rb_include_class_new(module, RCLASS_SUPER(c));
882  c = RCLASS_SET_SUPER(c, iclass);
883 
884  if (BUILTIN_TYPE(module) == T_ICLASS) {
885  rb_module_add_to_subclasses_list(RBASIC(module)->klass, iclass);
886  } else {
887  rb_module_add_to_subclasses_list(module, iclass);
888  }
889 
890  if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
891  VALUE refined_class =
893 
895  (st_data_t) refined_class);
897  }
898  if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
899  method_changed = 1;
900  if (RMODULE_CONST_TBL(module) && RMODULE_CONST_TBL(module)->num_entries)
901  constant_changed = 1;
902  skip:
903  module = RCLASS_SUPER(module);
904  }
905 
906  if (method_changed) rb_clear_method_cache_by_class(klass);
907  if (constant_changed) rb_clear_constant_cache();
908 
909  return method_changed;
910 }
911 
912 static int
914 {
915  rb_method_entry_t *me = (rb_method_entry_t *) value;
916  st_table *tbl = (st_table *) data;
917 
918  if (me->def->type == VM_METHOD_TYPE_REFINED) {
919  if (me->def->body.orig_me) {
920  rb_method_entry_t *orig_me = me->def->body.orig_me, *new_me;
921  me->def->body.orig_me = NULL;
922  new_me = ALLOC(rb_method_entry_t);
923  *new_me = *me;
924  st_add_direct(tbl, key, (st_data_t) new_me);
925  *me = *orig_me;
926  xfree(orig_me);
927  return ST_CONTINUE;
928  }
929  else {
930  st_add_direct(tbl, key, (st_data_t) me);
931  return ST_DELETE;
932  }
933  }
934  else {
935  return ST_CONTINUE;
936  }
937 }
938 
939 void
941 {
943  VALUE origin;
944  int changed = 0;
945 
946  rb_frozen_class_p(klass);
947 
948  Check_Type(module, T_MODULE);
949 
950  OBJ_INFECT(klass, module);
951 
952  origin = RCLASS_ORIGIN(klass);
953  if (origin == klass) {
954  origin = class_alloc(T_ICLASS, klass);
955  OBJ_WB_UNPROTECT(origin); /* TODO: conservertive shading. Need more survery. */
956  RCLASS_SET_SUPER(origin, RCLASS_SUPER(klass));
957  RCLASS_SET_SUPER(klass, origin);
958  RCLASS_ORIGIN(klass) = origin;
960  RCLASS_M_TBL_INIT(klass);
962  (st_data_t) RCLASS_M_TBL(klass));
963  }
964  changed = include_modules_at(klass, klass, module);
965  if (changed < 0)
966  rb_raise(rb_eArgError, "cyclic prepend detected");
967  if (changed) {
969  }
970 }
971 
972 /*
973  * call-seq:
974  * mod.included_modules -> array
975  *
976  * Returns the list of modules included in <i>mod</i>.
977  *
978  * module Mixin
979  * end
980  *
981  * module Outer
982  * include Mixin
983  * end
984  *
985  * Mixin.included_modules #=> []
986  * Outer.included_modules #=> [Mixin]
987  */
988 
989 VALUE
991 {
992  VALUE ary = rb_ary_new();
993  VALUE p;
994  VALUE origin = RCLASS_ORIGIN(mod);
995 
996  for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
997  if (p != origin && BUILTIN_TYPE(p) == T_ICLASS) {
998  VALUE m = RBASIC(p)->klass;
999  if (RB_TYPE_P(m, T_MODULE))
1000  rb_ary_push(ary, m);
1001  }
1002  }
1003  return ary;
1004 }
1005 
1006 /*
1007  * call-seq:
1008  * mod.include?(module) -> true or false
1009  *
1010  * Returns <code>true</code> if <i>module</i> is included in
1011  * <i>mod</i> or one of <i>mod</i>'s ancestors.
1012  *
1013  * module A
1014  * end
1015  * class B
1016  * include A
1017  * end
1018  * class C < B
1019  * end
1020  * B.include?(A) #=> true
1021  * C.include?(A) #=> true
1022  * A.include?(A) #=> false
1023  */
1024 
1025 VALUE
1027 {
1028  VALUE p;
1029 
1030  Check_Type(mod2, T_MODULE);
1031  for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
1032  if (BUILTIN_TYPE(p) == T_ICLASS) {
1033  if (RBASIC(p)->klass == mod2) return Qtrue;
1034  }
1035  }
1036  return Qfalse;
1037 }
1038 
1039 /*
1040  * call-seq:
1041  * mod.ancestors -> array
1042  *
1043  * Returns a list of modules included in <i>mod</i> (including
1044  * <i>mod</i> itself).
1045  *
1046  * module Mod
1047  * include Math
1048  * include Comparable
1049  * end
1050  *
1051  * Mod.ancestors #=> [Mod, Comparable, Math]
1052  * Math.ancestors #=> [Math]
1053  */
1054 
1055 VALUE
1057 {
1058  VALUE p, ary = rb_ary_new();
1059 
1060  for (p = mod; p; p = RCLASS_SUPER(p)) {
1061  if (BUILTIN_TYPE(p) == T_ICLASS) {
1062  rb_ary_push(ary, RBASIC(p)->klass);
1063  }
1064  else if (p == RCLASS_ORIGIN(p)) {
1065  rb_ary_push(ary, p);
1066  }
1067  }
1068  return ary;
1069 }
1070 
1071 #define VISI(x) ((x)&NOEX_MASK)
1072 #define VISI_CHECK(x,f) (VISI(x) == (f))
1073 
1074 static int
1075 ins_methods_push(ID name, long type, VALUE ary, long visi)
1076 {
1077  if (type == -1) return ST_CONTINUE;
1078 
1079  switch (visi) {
1080  case NOEX_PRIVATE:
1081  case NOEX_PROTECTED:
1082  case NOEX_PUBLIC:
1083  visi = (type == visi);
1084  break;
1085  default:
1086  visi = (type != NOEX_PRIVATE);
1087  break;
1088  }
1089  if (visi) {
1090  rb_ary_push(ary, ID2SYM(name));
1091  }
1092  return ST_CONTINUE;
1093 }
1094 
1095 static int
1097 {
1098  return ins_methods_push((ID)name, (long)type, (VALUE)ary, -1); /* everything but private */
1099 }
1100 
1101 static int
1103 {
1104  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PROTECTED);
1105 }
1106 
1107 static int
1109 {
1110  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PRIVATE);
1111 }
1112 
1113 static int
1115 {
1116  return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PUBLIC);
1117 }
1118 
1119 static int
1121 {
1122  const rb_method_entry_t *me = (const rb_method_entry_t *)value;
1123  st_table *list = (st_table *)data;
1124  long type;
1125 
1126  if (me && me->def->type == VM_METHOD_TYPE_REFINED) {
1127  me = rb_resolve_refined_method(Qnil, me, NULL);
1128  if (!me) return ST_CONTINUE;
1129  }
1130  if (!st_lookup(list, key, 0)) {
1131  if (UNDEFINED_METHOD_ENTRY_P(me)) {
1132  type = -1; /* none */
1133  }
1134  else {
1135  type = VISI(me->flag);
1136  }
1137  st_add_direct(list, key, type);
1138  }
1139  return ST_CONTINUE;
1140 }
1141 
1142 static VALUE
1144 {
1145  VALUE ary;
1146  int recur, prepended = 0;
1147  st_table *list;
1148 
1149  if (argc == 0) {
1150  recur = TRUE;
1151  }
1152  else {
1153  VALUE r;
1154  rb_scan_args(argc, argv, "01", &r);
1155  recur = RTEST(r);
1156  }
1157 
1158  if (!recur && RCLASS_ORIGIN(mod) != mod) {
1159  mod = RCLASS_ORIGIN(mod);
1160  prepended = 1;
1161  }
1162 
1163  list = st_init_numtable();
1164  for (; mod; mod = RCLASS_SUPER(mod)) {
1166  if (BUILTIN_TYPE(mod) == T_ICLASS && !prepended) continue;
1167  if (obj && FL_TEST(mod, FL_SINGLETON)) continue;
1168  if (!recur) break;
1169  }
1170  ary = rb_ary_new();
1171  st_foreach(list, func, ary);
1172  st_free_table(list);
1173 
1174  return ary;
1175 }
1176 
1177 /*
1178  * call-seq:
1179  * mod.instance_methods(include_super=true) -> array
1180  *
1181  * Returns an array containing the names of the public and protected instance
1182  * methods in the receiver. For a module, these are the public and protected methods;
1183  * for a class, they are the instance (not singleton) methods. With no
1184  * argument, or with an argument that is <code>false</code>, the
1185  * instance methods in <i>mod</i> are returned, otherwise the methods
1186  * in <i>mod</i> and <i>mod</i>'s superclasses are returned.
1187  *
1188  * module A
1189  * def method1() end
1190  * end
1191  * class B
1192  * def method2() end
1193  * end
1194  * class C < B
1195  * def method3() end
1196  * end
1197  *
1198  * A.instance_methods #=> [:method1]
1199  * B.instance_methods(false) #=> [:method2]
1200  * C.instance_methods(false) #=> [:method3]
1201  * C.instance_methods(true).length #=> 43
1202  */
1203 
1204 VALUE
1206 {
1207  return class_instance_method_list(argc, argv, mod, 0, ins_methods_i);
1208 }
1209 
1210 /*
1211  * call-seq:
1212  * mod.protected_instance_methods(include_super=true) -> array
1213  *
1214  * Returns a list of the protected instance methods defined in
1215  * <i>mod</i>. If the optional parameter is not <code>false</code>, the
1216  * methods of any ancestors are included.
1217  */
1218 
1219 VALUE
1221 {
1222  return class_instance_method_list(argc, argv, mod, 0, ins_methods_prot_i);
1223 }
1224 
1225 /*
1226  * call-seq:
1227  * mod.private_instance_methods(include_super=true) -> array
1228  *
1229  * Returns a list of the private instance methods defined in
1230  * <i>mod</i>. If the optional parameter is not <code>false</code>, the
1231  * methods of any ancestors are included.
1232  *
1233  * module Mod
1234  * def method1() end
1235  * private :method1
1236  * def method2() end
1237  * end
1238  * Mod.instance_methods #=> [:method2]
1239  * Mod.private_instance_methods #=> [:method1]
1240  */
1241 
1242 VALUE
1244 {
1245  return class_instance_method_list(argc, argv, mod, 0, ins_methods_priv_i);
1246 }
1247 
1248 /*
1249  * call-seq:
1250  * mod.public_instance_methods(include_super=true) -> array
1251  *
1252  * Returns a list of the public instance methods defined in <i>mod</i>.
1253  * If the optional parameter is not <code>false</code>, the methods of
1254  * any ancestors are included.
1255  */
1256 
1257 VALUE
1259 {
1260  return class_instance_method_list(argc, argv, mod, 0, ins_methods_pub_i);
1261 }
1262 
1263 /*
1264  * call-seq:
1265  * obj.methods(regular=true) -> array
1266  *
1267  * Returns a list of the names of public and protected methods of
1268  * <i>obj</i>. This will include all the methods accessible in
1269  * <i>obj</i>'s ancestors.
1270  * If the <i>regular</i> parameter is set to <code>false</code>,
1271  * Returns an array of obj's public and protected singleton methods,
1272  * the array will not include methods in modules included in <i>obj</i>.
1273  *
1274  * class Klass
1275  * def klass_method()
1276  * end
1277  * end
1278  * k = Klass.new
1279  * k.methods[0..9] #=> [:klass_method, :nil?, :===,
1280  * # :==~, :!, :eql?
1281  * # :hash, :<=>, :class, :singleton_class]
1282  * k.methods.length #=> 57
1283  *
1284  * k.methods(false) #=> []
1285  * def k.singleton_method; end
1286  * k.methods(false) #=> [:singleton_method]
1287  *
1288  * module M123; def m123; end end
1289  * k.extend M123
1290  * k.methods(false) #=> [:singleton_method]
1291  */
1292 
1293 VALUE
1294 rb_obj_methods(int argc, VALUE *argv, VALUE obj)
1295 {
1296  retry:
1297  if (argc == 0) {
1298  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_i);
1299  }
1300  else {
1301  VALUE recur;
1302 
1303  rb_scan_args(argc, argv, "1", &recur);
1304  if (RTEST(recur)) {
1305  argc = 0;
1306  goto retry;
1307  }
1308  return rb_obj_singleton_methods(argc, argv, obj);
1309  }
1310 }
1311 
1312 /*
1313  * call-seq:
1314  * obj.protected_methods(all=true) -> array
1315  *
1316  * Returns the list of protected methods accessible to <i>obj</i>. If
1317  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1318  * in the receiver will be listed.
1319  */
1320 
1321 VALUE
1322 rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj)
1323 {
1324  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_prot_i);
1325 }
1326 
1327 /*
1328  * call-seq:
1329  * obj.private_methods(all=true) -> array
1330  *
1331  * Returns the list of private methods accessible to <i>obj</i>. If
1332  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1333  * in the receiver will be listed.
1334  */
1335 
1336 VALUE
1337 rb_obj_private_methods(int argc, VALUE *argv, VALUE obj)
1338 {
1339  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_priv_i);
1340 }
1341 
1342 /*
1343  * call-seq:
1344  * obj.public_methods(all=true) -> array
1345  *
1346  * Returns the list of public methods accessible to <i>obj</i>. If
1347  * the <i>all</i> parameter is set to <code>false</code>, only those methods
1348  * in the receiver will be listed.
1349  */
1350 
1351 VALUE
1352 rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
1353 {
1354  return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_pub_i);
1355 }
1356 
1357 /*
1358  * call-seq:
1359  * obj.singleton_methods(all=true) -> array
1360  *
1361  * Returns an array of the names of singleton methods for <i>obj</i>.
1362  * If the optional <i>all</i> parameter is true, the list will include
1363  * methods in modules included in <i>obj</i>.
1364  * Only public and protected singleton methods are returned.
1365  *
1366  * module Other
1367  * def three() end
1368  * end
1369  *
1370  * class Single
1371  * def Single.four() end
1372  * end
1373  *
1374  * a = Single.new
1375  *
1376  * def a.one()
1377  * end
1378  *
1379  * class << a
1380  * include Other
1381  * def two()
1382  * end
1383  * end
1384  *
1385  * Single.singleton_methods #=> [:four]
1386  * a.singleton_methods(false) #=> [:two, :one]
1387  * a.singleton_methods #=> [:two, :one, :three]
1388  */
1389 
1390 VALUE
1391 rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
1392 {
1393  VALUE recur, ary, klass, origin;
1394  st_table *list, *mtbl;
1395 
1396  if (argc == 0) {
1397  recur = Qtrue;
1398  }
1399  else {
1400  rb_scan_args(argc, argv, "01", &recur);
1401  }
1402  klass = CLASS_OF(obj);
1403  origin = RCLASS_ORIGIN(klass);
1404  list = st_init_numtable();
1405  if (klass && FL_TEST(klass, FL_SINGLETON)) {
1406  if ((mtbl = RCLASS_M_TBL(origin)) != 0)
1407  st_foreach(mtbl, method_entry_i, (st_data_t)list);
1408  klass = RCLASS_SUPER(klass);
1409  }
1410  if (RTEST(recur)) {
1411  while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
1412  if (klass != origin && (mtbl = RCLASS_M_TBL(klass)) != 0)
1413  st_foreach(mtbl, method_entry_i, (st_data_t)list);
1414  klass = RCLASS_SUPER(klass);
1415  }
1416  }
1417  ary = rb_ary_new();
1418  st_foreach(list, ins_methods_i, ary);
1419  st_free_table(list);
1420 
1421  return ary;
1422 }
1423 
1481 void
1482 rb_define_method_id(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc)
1483 {
1484  rb_add_method_cfunc(klass, mid, func, argc, NOEX_PUBLIC);
1485 }
1486 
1487 void
1488 rb_define_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
1489 {
1490  rb_add_method_cfunc(klass, rb_intern(name), func, argc, NOEX_PUBLIC);
1491 }
1492 
1493 void
1494 rb_define_protected_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
1495 {
1496  rb_add_method_cfunc(klass, rb_intern(name), func, argc, NOEX_PROTECTED);
1497 }
1498 
1499 void
1500 rb_define_private_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
1501 {
1502  rb_add_method_cfunc(klass, rb_intern(name), func, argc, NOEX_PRIVATE);
1503 }
1504 
1505 void
1506 rb_undef_method(VALUE klass, const char *name)
1507 {
1509 }
1510 
1519 #define SPECIAL_SINGLETON(x,c) do {\
1520  if (obj == (x)) {\
1521  return (c);\
1522  }\
1523 } while (0)
1524 
1525 static inline VALUE
1527 {
1531  return Qnil;
1532 }
1533 
1534 VALUE
1536 {
1537  return special_singleton_class_of(obj);
1538 }
1539 
1549 static VALUE
1551 {
1552  VALUE klass;
1553 
1554  if (FIXNUM_P(obj) || FLONUM_P(obj) || SYMBOL_P(obj)) {
1555  rb_raise(rb_eTypeError, "can't define singleton");
1556  }
1557  if (SPECIAL_CONST_P(obj)) {
1558  klass = special_singleton_class_of(obj);
1559  if (NIL_P(klass))
1560  rb_bug("unknown immediate %p", (void *)obj);
1561  return klass;
1562  }
1563  else {
1564  enum ruby_value_type type = BUILTIN_TYPE(obj);
1565  if (type == T_FLOAT || type == T_BIGNUM) {
1566  rb_raise(rb_eTypeError, "can't define singleton");
1567  }
1568  }
1569 
1570  if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) &&
1571  rb_ivar_get(RBASIC(obj)->klass, id_attached) == obj) {
1572  klass = RBASIC(obj)->klass;
1573  }
1574  else {
1575  klass = rb_make_metaclass(obj, RBASIC(obj)->klass);
1576  }
1577 
1578  if (OBJ_TAINTED(obj)) {
1579  OBJ_TAINT(klass);
1580  }
1581  else {
1582  FL_UNSET(klass, FL_TAINT);
1583  }
1584  if (OBJ_FROZEN(obj)) OBJ_FREEZE(klass);
1585 
1586  return klass;
1587 }
1588 
1596 VALUE
1598 {
1599  VALUE klass;
1600 
1601  if (SPECIAL_CONST_P(obj)) {
1602  return rb_special_singleton_class(obj);
1603  }
1604  klass = RBASIC(obj)->klass;
1605  if (!FL_TEST(klass, FL_SINGLETON)) return Qnil;
1606  if (rb_ivar_get(klass, id_attached) != obj) return Qnil;
1607  return klass;
1608 }
1609 
1627 VALUE
1629 {
1630  VALUE klass = singleton_class_of(obj);
1631 
1632  /* ensures an exposed class belongs to its own eigenclass */
1633  if (RB_TYPE_P(obj, T_CLASS)) (void)ENSURE_EIGENCLASS(klass);
1634 
1635  return klass;
1636 }
1637 
1654 void
1655 rb_define_singleton_method(VALUE obj, const char *name, VALUE (*func)(ANYARGS), int argc)
1656 {
1657  rb_define_method(singleton_class_of(obj), name, func, argc);
1658 }
1659 
1660 
1661 
1669 void
1670 rb_define_module_function(VALUE module, const char *name, VALUE (*func)(ANYARGS), int argc)
1671 {
1672  rb_define_private_method(module, name, func, argc);
1673  rb_define_singleton_method(module, name, func, argc);
1674 }
1675 
1676 
1683 void
1684 rb_define_global_function(const char *name, VALUE (*func)(ANYARGS), int argc)
1685 {
1687 }
1688 
1689 
1696 void
1697 rb_define_alias(VALUE klass, const char *name1, const char *name2)
1698 {
1699  rb_alias(klass, rb_intern(name1), rb_intern(name2));
1700 }
1701 
1709 void
1710 rb_define_attr(VALUE klass, const char *name, int read, int write)
1711 {
1712  rb_attr(klass, rb_intern(name), read, write, FALSE);
1713 }
1714 
1715 int
1717 {
1718  const rb_method_entry_t *me = rb_method_entry(CLASS_OF(obj), rb_intern("to_s"), 0);
1719  if (me && me->def && me->def->type == VM_METHOD_TYPE_CFUNC &&
1720  me->def->body.cfunc.func == rb_any_to_s)
1721  return 1;
1722  return 0;
1723 }
1724 
1725 #include <stdarg.h>
1726 
1727 int
1728 rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
1729 {
1730  int i;
1731  const char *p = fmt;
1732  VALUE *var;
1733  va_list vargs;
1734  int f_var = 0, f_hash = 0, f_block = 0;
1735  int n_lead = 0, n_opt = 0, n_trail = 0, n_mand;
1736  int argi = 0;
1737  VALUE hash = Qnil;
1738 
1739  if (ISDIGIT(*p)) {
1740  n_lead = *p - '0';
1741  p++;
1742  if (ISDIGIT(*p)) {
1743  n_opt = *p - '0';
1744  p++;
1745  if (ISDIGIT(*p)) {
1746  n_trail = *p - '0';
1747  p++;
1748  goto block_arg;
1749  }
1750  }
1751  }
1752  if (*p == '*') {
1753  f_var = 1;
1754  p++;
1755  if (ISDIGIT(*p)) {
1756  n_trail = *p - '0';
1757  p++;
1758  }
1759  }
1760  block_arg:
1761  if (*p == ':') {
1762  f_hash = 1;
1763  p++;
1764  }
1765  if (*p == '&') {
1766  f_block = 1;
1767  p++;
1768  }
1769  if (*p != '\0') {
1770  rb_fatal("bad scan arg format: %s", fmt);
1771  }
1772  n_mand = n_lead + n_trail;
1773 
1774  if (argc < n_mand)
1775  goto argc_error;
1776 
1777  va_start(vargs, fmt);
1778 
1779  /* capture an option hash - phase 1: pop */
1780  if (f_hash && n_mand < argc) {
1781  VALUE last = argv[argc - 1];
1782 
1783  if (NIL_P(last)) {
1784  /* nil is taken as an empty option hash only if it is not
1785  ambiguous; i.e. '*' is not specified and arguments are
1786  given more than sufficient */
1787  if (!f_var && n_mand + n_opt < argc)
1788  argc--;
1789  }
1790  else {
1791  hash = rb_check_hash_type(last);
1792  if (!NIL_P(hash)) {
1793  VALUE opts = rb_extract_keywords(&hash);
1794  if (!hash) argc--;
1795  hash = opts ? opts : Qnil;
1796  }
1797  }
1798  }
1799  /* capture leading mandatory arguments */
1800  for (i = n_lead; i-- > 0; ) {
1801  var = va_arg(vargs, VALUE *);
1802  if (var) *var = argv[argi];
1803  argi++;
1804  }
1805  /* capture optional arguments */
1806  for (i = n_opt; i-- > 0; ) {
1807  var = va_arg(vargs, VALUE *);
1808  if (argi < argc - n_trail) {
1809  if (var) *var = argv[argi];
1810  argi++;
1811  }
1812  else {
1813  if (var) *var = Qnil;
1814  }
1815  }
1816  /* capture variable length arguments */
1817  if (f_var) {
1818  int n_var = argc - argi - n_trail;
1819 
1820  var = va_arg(vargs, VALUE *);
1821  if (0 < n_var) {
1822  if (var) *var = rb_ary_new4(n_var, &argv[argi]);
1823  argi += n_var;
1824  }
1825  else {
1826  if (var) *var = rb_ary_new();
1827  }
1828  }
1829  /* capture trailing mandatory arguments */
1830  for (i = n_trail; i-- > 0; ) {
1831  var = va_arg(vargs, VALUE *);
1832  if (var) *var = argv[argi];
1833  argi++;
1834  }
1835  /* capture an option hash - phase 2: assignment */
1836  if (f_hash) {
1837  var = va_arg(vargs, VALUE *);
1838  if (var) *var = hash;
1839  }
1840  /* capture iterator block */
1841  if (f_block) {
1842  var = va_arg(vargs, VALUE *);
1843  if (rb_block_given_p()) {
1844  *var = rb_block_proc();
1845  }
1846  else {
1847  *var = Qnil;
1848  }
1849  }
1850  va_end(vargs);
1851 
1852  if (argi < argc) {
1853  argc_error:
1854  rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt);
1855  }
1856 
1857  return argc;
1858 }
1859 
1860 NORETURN(static void keyword_error(const char *error, VALUE keys));
1861 static void
1862 keyword_error(const char *error, VALUE keys)
1863 {
1864  const char *msg = "";
1865  if (RARRAY_LEN(keys) == 1) {
1866  keys = RARRAY_AREF(keys, 0);
1867  }
1868  else {
1869  keys = rb_ary_join(keys, rb_usascii_str_new2(", "));
1870  msg = "s";
1871  }
1872  rb_raise(rb_eArgError, "%s keyword%s: %"PRIsVALUE, error, msg, keys);
1873 }
1874 
1875 NORETURN(static void unknown_keyword_error(VALUE hash, const ID *table, int keywords));
1876 static void
1877 unknown_keyword_error(VALUE hash, const ID *table, int keywords)
1878 {
1879  VALUE keys;
1880  int i;
1881  for (i = 0; i < keywords; i++) {
1882  rb_hash_delete(hash, ID2SYM(table[i]));
1883  }
1884  keys = rb_funcall(hash, rb_intern("keys"), 0, 0);
1885  if (!RB_TYPE_P(keys, T_ARRAY)) rb_raise(rb_eArgError, "unknown keyword");
1886  keyword_error("unknown", keys);
1887 }
1888 
1889 static int
1891 {
1892  VALUE *kwdhash = (VALUE *)arg;
1893 
1894  if (!SYMBOL_P(key)) kwdhash++;
1895  if (!*kwdhash) *kwdhash = rb_hash_new();
1896  rb_hash_aset(*kwdhash, (VALUE)key, (VALUE)value);
1897  return ST_CONTINUE;
1898 }
1899 
1900 VALUE
1902 {
1903  VALUE parthash[2] = {0, 0};
1904  VALUE hash = *orighash;
1905 
1906  if (RHASH_EMPTY_P(hash)) {
1907  *orighash = 0;
1908  return hash;
1909  }
1911  *orighash = parthash[1];
1912  return parthash[0];
1913 }
1914 
1915 int
1916 rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
1917 {
1918  int i = 0, j;
1919  int rest = 0;
1920  VALUE missing = Qnil;
1921  st_data_t key;
1922 
1923 #define extract_kwarg(keyword, val) \
1924  (key = (st_data_t)(keyword), values ? \
1925  st_delete(rb_hash_tbl_raw(keyword_hash), &key, (val)) : \
1926  st_lookup(rb_hash_tbl_raw(keyword_hash), key, (val)))
1927 
1928  if (optional < 0) {
1929  rest = 1;
1930  optional = -1-optional;
1931  }
1932  if (values) {
1933  for (j = 0; j < required + optional; j++) {
1934  values[j] = Qundef;
1935  }
1936  }
1937  if (required) {
1938  for (; i < required; i++) {
1939  VALUE keyword = ID2SYM(table[i]);
1940  if (keyword_hash) {
1941  st_data_t val;
1942  if (extract_kwarg(keyword, &val)) {
1943  if (values) values[i] = (VALUE)val;
1944  continue;
1945  }
1946  }
1947  if (NIL_P(missing)) missing = rb_ary_tmp_new(1);
1948  rb_ary_push(missing, keyword);
1949  }
1950  if (!NIL_P(missing)) {
1951  keyword_error("missing", missing);
1952  }
1953  }
1954  j = i;
1955  if (optional && keyword_hash) {
1956  for (i = 0; i < optional; i++) {
1957  st_data_t val;
1958  if (extract_kwarg(ID2SYM(table[required+i]), &val)) {
1959  if (values) values[required+i] = (VALUE)val;
1960  j++;
1961  }
1962  }
1963  }
1964  if (!rest && keyword_hash) {
1965  if (RHASH_SIZE(keyword_hash) > (unsigned int)j) {
1966  unknown_keyword_error(keyword_hash, table, required+optional);
1967  }
1968  }
1969  return j;
1970 #undef extract_kwarg
1971 }
1972 
static VALUE make_metaclass(VALUE klass)
Creates a metaclass of klass.
Definition: class.c:475
static void rb_module_add_to_subclasses_list(VALUE module, VALUE iclass)
Definition: class.c:61
static void rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr)
Definition: class.c:236
int rb_st_insert_id_and_value(VALUE obj, st_table *tbl, ID key, VALUE value)
Definition: variable.c:2618
void rb_class_remove_from_super_subclasses(VALUE klass)
Definition: class.c:80
#define ISDIGIT(c)
Definition: ruby.h:1775
#define UNDEFINED_METHOD_ENTRY_P(me)
Definition: method.h:110
Definition: st.h:100
void rb_class_detach_subclasses(VALUE klass)
Definition: class.c:131
VALUE rb_define_module_id_under(VALUE outer, ID id)
Definition: class.c:772
void rb_vm_check_redefinition_by_prepend(VALUE klass)
Definition: vm.c:1176
NODE *const cref_stack
Definition: vm_core.h:315
RUBY_EXTERN VALUE rb_cFalseClass
Definition: ruby.h:1561
VALUE rb_mod_include_p(VALUE mod, VALUE mod2)
Definition: class.c:1026
#define RARRAY_LEN(a)
Definition: ruby.h:878
void rb_bug(const char *fmt,...)
Definition: error.c:327
rb_method_type_t type
Definition: method.h:79
int rb_vm_add_root_module(ID id, VALUE module)
Definition: vm.c:1771
#define FALSE
Definition: nkf.h:174
void rb_check_inheritable(VALUE super)
Ensures a class can be derived from super.
Definition: class.c:206
static int ins_methods_push(ID name, long type, VALUE ary, long visi)
Definition: class.c:1075
#define RCLASS_CONST_TBL(c)
Definition: internal.h:293
Definition: constant.h:19
Definition: st.h:69
VALUE rb_obj_private_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1337
VALUE rb_id2str(ID id)
Definition: ripper.c:17157
#define VISI(x)
Definition: class.c:1071
#define RB_OBJ_WRITTEN(a, oldv, b)
Definition: ruby.h:1214
rb_subclass_entry_t * next
Definition: internal.h:250
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1655
void rb_class_foreach_subclass(VALUE klass, void(*f)(VALUE))
Definition: class.c:117
rb_method_flag_t flag
Definition: method.h:98
#define rb_usascii_str_new2
Definition: intern.h:846
VALUE rb_class_private_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1243
#define FL_TAINT
Definition: ruby.h:1137
#define CLASS_OF(v)
Definition: ruby.h:440
#define T_MODULE
Definition: ruby.h:480
VALUE rb_define_class_id_under(VALUE outer, ID id, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:699
const VALUE file
Definition: constant.h:22
#define RCLASS_EXT(c)
Definition: classext.h:15
void rb_class_remove_from_module_subclasses(VALUE klass)
Definition: class.c:98
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Definition: class.c:1916
#define Qtrue
Definition: ruby.h:426
int st_insert(st_table *, st_data_t, st_data_t)
static VALUE class_alloc(VALUE flags, VALUE klass)
Allocates a struct RClass for a new class.
Definition: class.c:155
#define OBJ_INIT_COPY(obj, orig)
Definition: intern.h:287
struct rb_method_entry_struct * orig_me
Definition: method.h:92
VALUE rb_mod_ancestors(VALUE mod)
Definition: class.c:1056
const int id
Definition: nkf.c:209
VALUE rb_refinement_module_get_refined_class(VALUE module)
Definition: eval.c:1177
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1500
VALUE rb_eTypeError
Definition: error.c:548
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:896
VALUE rb_singleton_class_clone(VALUE obj)
Definition: class.c:371
void st_free_table(st_table *)
Definition: st.c:334
struct st_table * rb_hash_tbl_raw(VALUE hash)
Definition: hash.c:351
VALUE rb_mod_init_copy(VALUE clone, VALUE orig)
Definition: class.c:319
VALUE rb_ary_tmp_new(long capa)
Definition: array.c:534
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:775
void Init_class_hierarchy(void)
Definition: class.c:535
#define RBASIC_SET_CLASS(obj, cls)
Definition: internal.h:609
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:676
#define Check_Type(v, t)
Definition: ruby.h:532
static int ins_methods_priv_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:1108
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1854
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1115
#define SET_METACLASS_OF(k, cls)
Definition: class.c:436
static int clone_const_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:298
#define RB_GC_GUARD(v)
Definition: ruby.h:523
void rb_clear_constant_cache(void)
Definition: vm_method.c:60
int rb_const_defined(VALUE, ID)
Definition: variable.c:2124
#define RCLASS_M_TBL_WRAPPER(c)
Definition: internal.h:294
const VALUE value
Definition: constant.h:21
union rb_method_definition_struct::@126 body
void rb_include_module(VALUE klass, VALUE module)
Definition: class.c:827
#define T_ARRAY
Definition: ruby.h:484
void rb_define_protected_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1494
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1684
unsigned int last
Definition: nkf.c:4310
#define RMODULE_M_TBL(m)
Definition: ruby.h:799
#define FIXNUM_P(f)
Definition: ruby.h:347
void rb_undef_method(VALUE klass, const char *name)
Definition: class.c:1506
#define OBJ_TAINTED(x)
Definition: ruby.h:1176
const char * rb_obj_classname(VALUE)
Definition: variable.c:406
#define head
Definition: st.c:107
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:20
void rb_name_error(ID id, const char *fmt,...)
Definition: error.c:967
Definition: node.h:239
#define NEWOBJ_OF(obj, type, klass, flags)
Definition: ruby.h:694
void rb_free_m_tbl_wrapper(struct method_table_wrapper *wrapper)
Definition: gc.c:1450
#define FL_SINGLETON
Definition: ruby.h:1133
void rb_prepend_module(VALUE klass, VALUE module)
Definition: class.c:940
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1628
VALUE rb_extract_keywords(VALUE *orighash)
Definition: class.c:1901
#define RB_TYPE_P(obj, type)
Definition: ruby.h:1664
int st_lookup(st_table *, st_data_t, st_data_t *)
rb_method_cfunc_t cfunc
Definition: method.h:83
#define FL_TEST(x, f)
Definition: ruby.h:1169
VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
Definition: class.c:604
NORETURN(static void keyword_error(const char *error, VALUE keys))
Definition: internal.h:248
int rb_block_given_p(void)
Definition: eval.c:712
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Definition: hash.c:1393
#define val
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1553
VALUE rb_special_singleton_class(VALUE obj)
Definition: class.c:1535
#define RMODULE_IS_REFINEMENT
Definition: ruby.h:802
#define RGENGC_WB_PROTECTED_CLASS
Definition: ruby.h:729
void rb_attr(VALUE, ID, int, int, int)
Definition: vm_method.c:859
static VALUE boot_defclass(const char *name, VALUE super)
Definition: class.c:524
VALUE rb_class_real(VALUE)
Definition: object.c:204
RUBY_EXTERN VALUE rb_cBasicObject
Definition: ruby.h:1552
VALUE rb_ary_new(void)
Definition: array.c:495
static void clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
Definition: class.c:255
#define RMODULE_CONST_TBL(m)
Definition: ruby.h:798
#define OBJ_WB_UNPROTECT(x)
Definition: ruby.h:1191
RUBY_EXTERN VALUE rb_mKernel
Definition: ruby.h:1541
#define RCLASS_ORIGIN(c)
Definition: internal.h:297
#define NIL_P(v)
Definition: ruby.h:438
static VALUE RCLASS_SET_SUPER(VALUE klass, VALUE super)
Definition: internal.h:319
void st_add_direct(st_table *, st_data_t, st_data_t)
Definition: st.c:629
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:630
static char msg[50]
Definition: strerror.c:8
RUBY_EXTERN VALUE rb_cTrueClass
Definition: ruby.h:1588
static VALUE special_singleton_class_of(VALUE obj)
Definition: class.c:1526
int st_delete(st_table *, st_data_t *, st_data_t *)
#define RCLASS_IV_TBL(c)
Definition: internal.h:292
void rb_class_subclass_add(VALUE super, VALUE klass)
Definition: class.c:40
VALUE rb_define_module_id(ID id)
Definition: class.c:735
#define METACLASS_OF(k)
Definition: class.c:435
#define OBJ_FROZEN(x)
Definition: ruby.h:1185
#define FLONUM_P(x)
Definition: ruby.h:367
#define META_CLASS_OF_CLASS_CLASS_P(k)
whether k is a meta^(n)-class of Class class
Definition: class.c:443
#define T_FLOAT
Definition: ruby.h:481
int argc
Definition: ruby.c:131
#define Qfalse
Definition: ruby.h:425
Definition: method.h:97
static void RCLASS_M_TBL_INIT(VALUE c)
Definition: internal.h:302
RUBY_EXTERN VALUE rb_cModule
Definition: ruby.h:1572
#define T_BIGNUM
Definition: ruby.h:487
void rb_gc_register_mark_object(VALUE obj)
Definition: gc.c:4920
#define MEMCPY(p1, p2, type, n)
Definition: ruby.h:1352
VALUE rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1322
#define rb_ary_new4
Definition: intern.h:92
#define OBJ_FREEZE(x)
Definition: ruby.h:1186
rb_method_entry_t * rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me, VALUE *defined_class_ptr)
Definition: vm_method.c:654
rb_method_entry_t * rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr)
Definition: vm_method.c:616
VALUE(* func)(ANYARGS)
Definition: method.h:66
VALUE klass
Definition: method.h:102
#define ALLOC(type)
Definition: ruby.h:1334
int rb_obj_basic_to_s_p(VALUE obj)
Definition: class.c:1716
#define RCLASS_REFINED_CLASS(c)
Definition: internal.h:298
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:1880
#define id_attached
Definition: class.c:37
VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase)
Definition: iseq.c:1922
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
Definition: class.c:1697
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
Definition: class.c:1670
#define RCLASS_M_TBL(c)
Definition: internal.h:295
static int add_refined_method_entry_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:845
rb_iseq_t *const iseq
Definition: method.h:82
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
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:1143
#define TRUE
Definition: nkf.h:175
VALUE rb_hash_delete(VALUE hash, VALUE key)
Definition: hash.c:996
VALUE rb_include_class_new(VALUE module, VALUE super)
Definition: class.c:792
void rb_fatal(const char *fmt,...)
Definition: error.c:1908
VALUE klass
Definition: internal.h:249
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:427
VALUE rb_hash_new(void)
Definition: hash.c:298
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1728
VALUE rb_check_hash_type(VALUE hash)
Definition: hash.c:588
#define PRIsVALUE
Definition: ruby.h:137
unsigned long ID
Definition: ruby.h:89
static int separate_symbol(st_data_t key, st_data_t value, st_data_t arg)
Definition: class.c:1890
#define RHASH_SIZE(h)
Definition: ruby.h:930
static int ins_methods_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:1096
#define Qnil
Definition: ruby.h:427
void rb_clear_method_cache_by_class(VALUE)
Definition: vm_method.c:66
void rb_const_set(VALUE, ID, VALUE)
Definition: variable.c:2160
#define extract_kwarg(keyword, val)
int type
Definition: tcltklib.c:112
static int include_modules_at(const VALUE klass, VALUE c, VALUE module)
Definition: class.c:852
VALUE rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1352
static int ins_methods_pub_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:1114
#define BUILTIN_TYPE(x)
Definition: ruby.h:502
#define OBJ_TAINT(x)
Definition: ruby.h:1177
unsigned long VALUE
Definition: ruby.h:88
void rb_name_class(VALUE, ID)
Definition: variable.c:385
#define RBASIC(obj)
Definition: ruby.h:1116
const char * rb_class2name(VALUE)
Definition: variable.c:397
VALUE rb_make_metaclass(VALUE obj, VALUE unused)
Definition: class.c:561
void rb_alias(VALUE, ID, ID)
Definition: vm_method.c:1243
static int clone_const(ID key, const rb_const_entry_t *ce, struct clone_const_arg *arg)
Definition: class.c:286
st_table * tbl
Definition: class.c:282
RUBY_EXTERN VALUE rb_cClass
Definition: ruby.h:1557
st_table * st_init_numtable(void)
Definition: st.c:272
void rb_class_detach_module_subclasses(VALUE klass)
Definition: class.c:137
ruby_value_type
Definition: ruby.h:442
VALUE rb_class_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1205
#define FL_UNSET(x, f)
Definition: ruby.h:1173
void rb_free_const_table(st_table *tbl)
Definition: gc.c:1466
VALUE rb_define_module_under(VALUE outer, const char *name)
Definition: class.c:766
#define recur(fmt)
VALUE rb_class_protected_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1220
int rb_const_defined_at(VALUE, ID)
Definition: variable.c:2130
void rb_define_method_id(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1482
VALUE rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1258
void rb_singleton_class_attached(VALUE klass, VALUE obj)
Attach a object to a singleton class.
Definition: class.c:423
#define f
static void unknown_keyword_error(VALUE hash, const ID *table, int keywords)
Definition: class.c:1877
#define UNLIMITED_ARGUMENTS
Definition: intern.h:44
#define RCLASS_SUPER(c)
Definition: classext.h:16
VALUE rb_module_new(void)
Definition: class.c:727
#define RARRAY_AREF(a, i)
Definition: ruby.h:901
#define ENSURE_EIGENCLASS(klass)
ensures klass belongs to its own eigenclass.
Definition: class.c:461
VALUE rb_block_proc(void)
Definition: proc.c:641
#define xmalloc
Definition: defines.h:108
VALUE rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1391
rb_method_definition_t * def
Definition: method.h:100
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:1710
#define ANYARGS
Definition: defines.h:98
void rb_error_arity(int argc, int min, int max)
#define RCLASS_IV_INDEX_TBL(c)
Definition: internal.h:296
#define FL_WB_PROTECTED
Definition: ruby.h:1134
#define NEW_CREF(a)
Definition: node.h:452
uint8_t key[16]
Definition: random.c:1250
static VALUE make_singleton_class(VALUE obj)
Creates a singleton class for obj.
Definition: class.c:509
VALUE rb_singleton_class_get(VALUE obj)
Returns the singleton class of obj, or nil if obj is not a singleton object.
Definition: class.c:1597
VALUE rb_any_to_s(VALUE)
Definition: object.c:453
#define RTEST(v)
Definition: ruby.h:437
static int method_entry_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:1120
st_table * rb_st_copy(VALUE obj, struct st_table *orig_tbl)
Definition: variable.c:2633
#define OBJ_INFECT(x, s)
Definition: ruby.h:1180
struct rb_encoding_entry * list
Definition: encoding.c:47
VALUE rb_obj_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1294
void rb_add_refined_method_entry(VALUE refined_class, ID mid)
Definition: vm_method.c:220
VALUE klass
Definition: class.c:281
static int ins_methods_prot_i(st_data_t name, st_data_t type, st_data_t ary)
Definition: class.c:1102
static unsigned int hash(const char *str, unsigned int len)
Definition: lex.c:56
VALUE rb_ary_join(VALUE ary, VALUE sep)
Definition: array.c:1994
#define T_CLASS
Definition: ruby.h:478
static int move_refined_method(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:913
VALUE rb_const_get_at(VALUE, ID)
Definition: variable.c:1886
void rb_frozen_class_p(VALUE klass)
Definition: eval.c:406
const char * name
Definition: nkf.c:208
static void class_init_copy_check(VALUE clone, VALUE orig)
Definition: class.c:304
#define FL_SET(x, f)
Definition: ruby.h:1172
VALUE self
Definition: vm_core.h:303
#define ID2SYM(x)
Definition: ruby.h:355
#define GetISeqPtr(obj, ptr)
Definition: vm_core.h:193
#define RMODULE_INCLUDED_INTO_REFINEMENT
Definition: ruby.h:803
const char * rb_id2name(ID id)
Definition: ripper.c:17227
VALUE rb_mod_included_modules(VALUE mod)
Definition: class.c:990
VALUE rb_define_class_id(ID id, VALUE super)
Defines a new class.
Definition: class.c:583
rb_serial_t rb_next_class_serial(void)
Definition: vm.c:92
#define SPECIAL_SINGLETON(x, c)
Definition: class.c:1519
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:503
#define CONST_ID(var, str)
Definition: ruby.h:1428
#define SPECIAL_CONST_P(x)
Definition: ruby.h:1165
void void xfree(void *)
#define RHASH_EMPTY_P(h)
Definition: ruby.h:931
VALUE rb_define_module(const char *name)
Definition: class.c:746
#define rb_intern(str)
#define SYMBOL_P(x)
Definition: ruby.h:354
#define mod(x, y)
Definition: date_strftime.c:28
static void keyword_error(const char *error, VALUE keys)
Definition: class.c:1862
#define NULL
Definition: _sdbm.c:103
static VALUE singleton_class_of(VALUE obj)
Definition: class.c:1550
Definition: ruby.h:790
static int clone_method_i(st_data_t key, st_data_t value, st_data_t data)
Definition: class.c:274
#define Qundef
Definition: ruby.h:428
#define T_ICLASS
Definition: ruby.h:479
#define RCLASS_SERIAL(c)
Definition: internal.h:299
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc, rb_method_flag_t noex)
Definition: vm_method.c:99
VALUE rb_class_new(VALUE super)
Creates a new class.
Definition: class.c:228
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1488
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
Definition: st.c:1034
void rb_warn(const char *fmt,...)
Definition: error.c:223
VALUE rb_class_boot(VALUE super)
A utility function that wraps class_alloc.
Definition: class.c:187
RUBY_EXTERN VALUE rb_cNilClass
Definition: ruby.h:1574
VALUE rb_eArgError
Definition: error.c:549
#define T_MASK
Definition: md5.c:131
void rb_set_class_path_string(VALUE, VALUE, VALUE)
Definition: variable.c:293
#define RB_OBJ_WRITE(a, slot, b)
Definition: ruby.h:1213
char ** argv
Definition: ruby.c:132
VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
Definition: class.c:377