Ruby  2.1.3p242(2014-09-19revision47630)
object.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  object.c -
4 
5  $Author: nagachika $
6  created at: Thu Jul 15 12:01:24 JST 1993
7 
8  Copyright (C) 1993-2007 Yukihiro Matsumoto
9  Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
10  Copyright (C) 2000 Information-technology Promotion Agency, Japan
11 
12 **********************************************************************/
13 
14 #include "ruby/ruby.h"
15 #include "ruby/st.h"
16 #include "ruby/util.h"
17 #include "ruby/encoding.h"
18 #include <stdio.h>
19 #include <errno.h>
20 #include <ctype.h>
21 #include <math.h>
22 #include <float.h>
23 #include "constant.h"
24 #include "internal.h"
25 #include "id.h"
26 #include "probes.h"
27 
34 
38 
39 #define id_eq idEq
40 #define id_eql idEqlP
41 #define id_match idEqTilde
42 #define id_inspect idInspect
43 #define id_init_copy idInitialize_copy
44 #define id_init_clone idInitialize_clone
45 #define id_init_dup idInitialize_dup
46 #define id_const_missing idConst_missing
47 
48 #define CLASS_OR_MODULE_P(obj) \
49  (!SPECIAL_CONST_P(obj) && \
50  (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
51 
52 VALUE
54 {
55  if (!SPECIAL_CONST_P(obj)) {
56  RBASIC_CLEAR_CLASS(obj);
57  }
58  return obj;
59 }
60 
61 VALUE
63 {
64  if (!SPECIAL_CONST_P(obj)) {
65  RBASIC_SET_CLASS(obj, klass);
66  }
67  return obj;
68 }
69 
70 VALUE
72 {
73  RBASIC(obj)->flags = type;
74  RBASIC_SET_CLASS(obj, klass);
75  if (rb_safe_level() >= 3) FL_SET((obj), FL_TAINT);
76  return obj;
77 }
78 
79 /*
80  * call-seq:
81  * obj === other -> true or false
82  *
83  * Case Equality -- For class Object, effectively the same as calling
84  * <code>#==</code>, but typically overridden by descendants to provide
85  * meaningful semantics in +case+ statements.
86  */
87 
88 VALUE
89 rb_equal(VALUE obj1, VALUE obj2)
90 {
91  VALUE result;
92 
93  if (obj1 == obj2) return Qtrue;
94  result = rb_funcall(obj1, id_eq, 1, obj2);
95  if (RTEST(result)) return Qtrue;
96  return Qfalse;
97 }
98 
99 int
100 rb_eql(VALUE obj1, VALUE obj2)
101 {
102  return RTEST(rb_funcall(obj1, id_eql, 1, obj2));
103 }
104 
105 /*
106  * call-seq:
107  * obj == other -> true or false
108  * obj.equal?(other) -> true or false
109  * obj.eql?(other) -> true or false
110  *
111  * Equality --- At the <code>Object</code> level, <code>==</code> returns
112  * <code>true</code> only if +obj+ and +other+ are the same object.
113  * Typically, this method is overridden in descendant classes to provide
114  * class-specific meaning.
115  *
116  * Unlike <code>==</code>, the <code>equal?</code> method should never be
117  * overridden by subclasses as it is used to determine object identity
118  * (that is, <code>a.equal?(b)</code> if and only if <code>a</code> is the
119  * same object as <code>b</code>):
120  *
121  * obj = "a"
122  * other = obj.dup
123  *
124  * obj == other #=> true
125  * obj.equal? other #=> false
126  * obj.equal? obj #=> true
127  *
128  * The <code>eql?</code> method returns <code>true</code> if +obj+ and
129  * +other+ refer to the same hash key. This is used by Hash to test members
130  * for equality. For objects of class <code>Object</code>, <code>eql?</code>
131  * is synonymous with <code>==</code>. Subclasses normally continue this
132  * tradition by aliasing <code>eql?</code> to their overridden <code>==</code>
133  * method, but there are exceptions. <code>Numeric</code> types, for
134  * example, perform type conversion across <code>==</code>, but not across
135  * <code>eql?</code>, so:
136  *
137  * 1 == 1.0 #=> true
138  * 1.eql? 1.0 #=> false
139  */
140 
141 VALUE
143 {
144  if (obj1 == obj2) return Qtrue;
145  return Qfalse;
146 }
147 
148 /*
149  * Generates a Fixnum hash value for this object. This function must have the
150  * property that <code>a.eql?(b)</code> implies <code>a.hash == b.hash</code>.
151  *
152  * The hash value is used along with #eql? by the Hash class to determine if
153  * two objects reference the same hash key. Any hash value that exceeds the
154  * capacity of a Fixnum will be truncated before being used.
155  *
156  * The hash value for an object may not be identical across invocations or
157  * implementations of ruby. If you need a stable identifier across ruby
158  * invocations and implementations you will need to generate one with a custom
159  * method.
160  */
161 VALUE
163 {
164  long rb_objid_hash(st_index_t index);
165  VALUE oid = rb_obj_id(obj);
166 #if SIZEOF_LONG == SIZEOF_VOIDP
167  st_index_t index = NUM2LONG(oid);
168 #elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
169  st_index_t index = NUM2LL(oid);
170 #else
171 # error not supported
172 #endif
173  return LONG2FIX(rb_objid_hash(index));
174 }
175 
176 /*
177  * call-seq:
178  * !obj -> true or false
179  *
180  * Boolean negate.
181  */
182 
183 VALUE
185 {
186  return RTEST(obj) ? Qfalse : Qtrue;
187 }
188 
189 /*
190  * call-seq:
191  * obj != other -> true or false
192  *
193  * Returns true if two objects are not-equal, otherwise false.
194  */
195 
196 VALUE
198 {
199  VALUE result = rb_funcall(obj1, id_eq, 1, obj2);
200  return RTEST(result) ? Qfalse : Qtrue;
201 }
202 
203 VALUE
205 {
206  if (cl == 0)
207  return 0;
208  while ((RBASIC(cl)->flags & FL_SINGLETON) || BUILTIN_TYPE(cl) == T_ICLASS) {
209  cl = RCLASS_SUPER(cl);
210  }
211  return cl;
212 }
213 
214 /*
215  * call-seq:
216  * obj.class -> class
217  *
218  * Returns the class of <i>obj</i>. This method must always be
219  * called with an explicit receiver, as <code>class</code> is also a
220  * reserved word in Ruby.
221  *
222  * 1.class #=> Fixnum
223  * self.class #=> Object
224  */
225 
226 VALUE
228 {
229  return rb_class_real(CLASS_OF(obj));
230 }
231 
232 /*
233  * call-seq:
234  * obj.singleton_class -> class
235  *
236  * Returns the singleton class of <i>obj</i>. This method creates
237  * a new singleton class if <i>obj</i> does not have it.
238  *
239  * If <i>obj</i> is <code>nil</code>, <code>true</code>, or
240  * <code>false</code>, it returns NilClass, TrueClass, or FalseClass,
241  * respectively.
242  * If <i>obj</i> is a Fixnum or a Symbol, it raises a TypeError.
243  *
244  * Object.new.singleton_class #=> #<Class:#<Object:0xb7ce1e24>>
245  * String.singleton_class #=> #<Class:String>
246  * nil.singleton_class #=> NilClass
247  */
248 
249 static VALUE
251 {
252  return rb_singleton_class(obj);
253 }
254 
255 void
257 {
258  if (!(RBASIC(dest)->flags & ROBJECT_EMBED) && ROBJECT_IVPTR(dest)) {
259  xfree(ROBJECT_IVPTR(dest));
260  ROBJECT(dest)->as.heap.ivptr = 0;
261  ROBJECT(dest)->as.heap.numiv = 0;
262  ROBJECT(dest)->as.heap.iv_index_tbl = 0;
263  }
264  if (RBASIC(obj)->flags & ROBJECT_EMBED) {
265  MEMCPY(ROBJECT(dest)->as.ary, ROBJECT(obj)->as.ary, VALUE, ROBJECT_EMBED_LEN_MAX);
266  RBASIC(dest)->flags |= ROBJECT_EMBED;
267  }
268  else {
269  long len = ROBJECT(obj)->as.heap.numiv;
270  VALUE *ptr = 0;
271  if (len > 0) {
272  ptr = ALLOC_N(VALUE, len);
273  MEMCPY(ptr, ROBJECT(obj)->as.heap.ivptr, VALUE, len);
274  }
275  ROBJECT(dest)->as.heap.ivptr = ptr;
276  ROBJECT(dest)->as.heap.numiv = len;
277  ROBJECT(dest)->as.heap.iv_index_tbl = ROBJECT(obj)->as.heap.iv_index_tbl;
278  RBASIC(dest)->flags &= ~ROBJECT_EMBED;
279  }
280 }
281 
282 static void
284 {
285  if (OBJ_FROZEN(dest)) {
286  rb_raise(rb_eTypeError, "[bug] frozen object (%s) allocated", rb_obj_classname(dest));
287  }
288  RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR);
289  RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR|FL_TAINT);
290  rb_copy_generic_ivar(dest, obj);
291  rb_gc_copy_finalizer(dest, obj);
292  switch (TYPE(obj)) {
293  case T_OBJECT:
294  rb_obj_copy_ivar(dest, obj);
295  break;
296  case T_CLASS:
297  case T_MODULE:
298  if (RCLASS_IV_TBL(dest)) {
300  RCLASS_IV_TBL(dest) = 0;
301  }
302  if (RCLASS_CONST_TBL(dest)) {
304  RCLASS_CONST_TBL(dest) = 0;
305  }
306  if (RCLASS_IV_TBL(obj)) {
307  RCLASS_IV_TBL(dest) = rb_st_copy(dest, RCLASS_IV_TBL(obj));
308  }
309  break;
310  }
311 }
312 
313 /*
314  * call-seq:
315  * obj.clone -> an_object
316  *
317  * Produces a shallow copy of <i>obj</i>---the instance variables of
318  * <i>obj</i> are copied, but not the objects they reference. Copies
319  * the frozen and tainted state of <i>obj</i>. See also the discussion
320  * under <code>Object#dup</code>.
321  *
322  * class Klass
323  * attr_accessor :str
324  * end
325  * s1 = Klass.new #=> #<Klass:0x401b3a38>
326  * s1.str = "Hello" #=> "Hello"
327  * s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello">
328  * s2.str[1,4] = "i" #=> "i"
329  * s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
330  * s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
331  *
332  * This method may have class-specific behavior. If so, that
333  * behavior will be documented under the #+initialize_copy+ method of
334  * the class.
335  */
336 
337 VALUE
339 {
340  VALUE clone;
341  VALUE singleton;
342 
343  if (rb_special_const_p(obj)) {
344  rb_raise(rb_eTypeError, "can't clone %s", rb_obj_classname(obj));
345  }
346  clone = rb_obj_alloc(rb_obj_class(obj));
347  RBASIC(clone)->flags &= (FL_TAINT|FL_PROMOTED|FL_WB_PROTECTED);
348  RBASIC(clone)->flags |= RBASIC(obj)->flags & ~(FL_PROMOTED|FL_FREEZE|FL_FINALIZE|FL_WB_PROTECTED);
349 
350  singleton = rb_singleton_class_clone_and_attach(obj, clone);
351  RBASIC_SET_CLASS(clone, singleton);
352  if (FL_TEST(singleton, FL_SINGLETON)) {
353  rb_singleton_class_attached(singleton, clone);
354  }
355 
356  init_copy(clone, obj);
357  rb_funcall(clone, id_init_clone, 1, obj);
358  RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE;
359 
360  return clone;
361 }
362 
363 /*
364  * call-seq:
365  * obj.dup -> an_object
366  *
367  * Produces a shallow copy of <i>obj</i>---the instance variables of
368  * <i>obj</i> are copied, but not the objects they reference. <code>dup</code>
369  * copies the tainted state of <i>obj</i>.
370  *
371  * This method may have class-specific behavior. If so, that
372  * behavior will be documented under the #+initialize_copy+ method of
373  * the class.
374  *
375  * === on dup vs clone
376  *
377  * In general, <code>clone</code> and <code>dup</code> may have different
378  * semantics in descendant classes. While <code>clone</code> is used to
379  * duplicate an object, including its internal state, <code>dup</code>
380  * typically uses the class of the descendant object to create the new
381  * instance.
382  *
383  * When using #dup any modules that the object has been extended with will not
384  * be copied.
385  *
386  * class Klass
387  * attr_accessor :str
388  * end
389  *
390  * module Foo
391  * def foo; 'foo'; end
392  * end
393  *
394  * s1 = Klass.new #=> #<Klass:0x401b3a38>
395  * s1.extend(Foo) #=> #<Klass:0x401b3a38>
396  * s1.foo #=> "foo"
397  *
398  * s2 = s1.clone #=> #<Klass:0x401b3a38>
399  * s2.foo #=> "foo"
400  *
401  * s3 = s1.dup #=> #<Klass:0x401b3a38>
402  * s3.foo #=> NoMethodError: undefined method `foo' for #<Klass:0x401b3a38>
403  *
404  */
405 
406 VALUE
408 {
409  VALUE dup;
410 
411  if (rb_special_const_p(obj)) {
412  rb_raise(rb_eTypeError, "can't dup %s", rb_obj_classname(obj));
413  }
414  dup = rb_obj_alloc(rb_obj_class(obj));
415  init_copy(dup, obj);
416  rb_funcall(dup, id_init_dup, 1, obj);
417 
418  return dup;
419 }
420 
421 /* :nodoc: */
422 VALUE
424 {
425  if (obj == orig) return obj;
426  rb_check_frozen(obj);
427  rb_check_trusted(obj);
428  if (TYPE(obj) != TYPE(orig) || rb_obj_class(obj) != rb_obj_class(orig)) {
429  rb_raise(rb_eTypeError, "initialize_copy should take same class object");
430  }
431  return obj;
432 }
433 
434 /* :nodoc: */
435 VALUE
437 {
438  rb_funcall(obj, id_init_copy, 1, orig);
439  return obj;
440 }
441 
442 /*
443  * call-seq:
444  * obj.to_s -> string
445  *
446  * Returns a string representing <i>obj</i>. The default
447  * <code>to_s</code> prints the object's class and an encoding of the
448  * object id. As a special case, the top-level object that is the
449  * initial execution context of Ruby programs returns ``main.''
450  */
451 
452 VALUE
454 {
455  VALUE str;
456  VALUE cname = rb_class_name(CLASS_OF(obj));
457 
458  str = rb_sprintf("#<%"PRIsVALUE":%p>", cname, (void*)obj);
459  OBJ_INFECT(str, obj);
460 
461  return str;
462 }
463 
464 /*
465  * If the default external encoding is ASCII compatible, the encoding of
466  * inspected result must be compatible with it.
467  * If the default external encoding is ASCII incompatible,
468  * the result must be ASCII only.
469  */
470 VALUE
472 {
473  VALUE str = rb_obj_as_string(rb_funcall(obj, id_inspect, 0, 0));
475  if (!rb_enc_asciicompat(ext)) {
476  if (!rb_enc_str_asciionly_p(str))
477  rb_raise(rb_eEncCompatError, "inspected result must be ASCII only if default external encoding is ASCII incompatible");
478  return str;
479  }
480  if (rb_enc_get(str) != ext && !rb_enc_str_asciionly_p(str))
481  rb_raise(rb_eEncCompatError, "inspected result must be ASCII only or use the default external encoding");
482  return str;
483 }
484 
485 static int
487 {
488  ID id = (ID)k;
489  VALUE value = (VALUE)v;
490  VALUE str = (VALUE)a;
491  VALUE str2;
492  const char *ivname;
493 
494  /* need not to show internal data */
495  if (CLASS_OF(value) == 0) return ST_CONTINUE;
496  if (!rb_is_instance_id(id)) return ST_CONTINUE;
497  if (RSTRING_PTR(str)[0] == '-') { /* first element */
498  RSTRING_PTR(str)[0] = '#';
499  rb_str_cat2(str, " ");
500  }
501  else {
502  rb_str_cat2(str, ", ");
503  }
504  ivname = rb_id2name(id);
505  rb_str_cat2(str, ivname);
506  rb_str_cat2(str, "=");
507  str2 = rb_inspect(value);
508  rb_str_append(str, str2);
509  OBJ_INFECT(str, str2);
510 
511  return ST_CONTINUE;
512 }
513 
514 static VALUE
515 inspect_obj(VALUE obj, VALUE str, int recur)
516 {
517  if (recur) {
518  rb_str_cat2(str, " ...");
519  }
520  else {
521  rb_ivar_foreach(obj, inspect_i, str);
522  }
523  rb_str_cat2(str, ">");
524  RSTRING_PTR(str)[0] = '#';
525  OBJ_INFECT(str, obj);
526 
527  return str;
528 }
529 
530 /*
531  * call-seq:
532  * obj.inspect -> string
533  *
534  * Returns a string containing a human-readable representation of <i>obj</i>.
535  * By default, show the class name and the list of the instance variables and
536  * their values (by calling #inspect on each of them).
537  * User defined classes should override this method to make better
538  * representation of <i>obj</i>. When overriding this method, it should
539  * return a string whose encoding is compatible with the default external
540  * encoding.
541  *
542  * [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]"
543  * Time.new.inspect #=> "2008-03-08 19:43:39 +0900"
544  *
545  * class Foo
546  * end
547  * Foo.new.inspect #=> "#<Foo:0x0300c868>"
548  *
549  * class Bar
550  * def initialize
551  * @bar = 1
552  * end
553  * end
554  * Bar.new.inspect #=> "#<Bar:0x0300c868 @bar=1>"
555  *
556  * class Baz
557  * def to_s
558  * "baz"
559  * end
560  * end
561  * Baz.new.inspect #=> "#<Baz:0x0300c868>"
562  */
563 
564 static VALUE
566 {
567  if (rb_ivar_count(obj) > 0) {
568  VALUE str;
569  VALUE c = rb_class_name(CLASS_OF(obj));
570 
571  str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void*)obj);
572  return rb_exec_recursive(inspect_obj, obj, str);
573  }
574  else {
575  return rb_any_to_s(obj);
576  }
577 }
578 
579 static VALUE
581 {
582  if (SPECIAL_CONST_P(c)) goto not_class;
583  switch (BUILTIN_TYPE(c)) {
584  case T_MODULE:
585  case T_CLASS:
586  case T_ICLASS:
587  break;
588 
589  default:
590  not_class:
591  rb_raise(rb_eTypeError, "class or module required");
592  }
593  return c;
594 }
595 
596 static VALUE class_search_ancestor(VALUE cl, VALUE c);
597 
598 /*
599  * call-seq:
600  * obj.instance_of?(class) -> true or false
601  *
602  * Returns <code>true</code> if <i>obj</i> is an instance of the given
603  * class. See also <code>Object#kind_of?</code>.
604  *
605  * class A; end
606  * class B < A; end
607  * class C < B; end
608  *
609  * b = B.new
610  * b.instance_of? A #=> false
611  * b.instance_of? B #=> true
612  * b.instance_of? C #=> false
613  */
614 
615 VALUE
617 {
619  if (rb_obj_class(obj) == c) return Qtrue;
620  return Qfalse;
621 }
622 
623 
624 /*
625  * call-seq:
626  * obj.is_a?(class) -> true or false
627  * obj.kind_of?(class) -> true or false
628  *
629  * Returns <code>true</code> if <i>class</i> is the class of
630  * <i>obj</i>, or if <i>class</i> is one of the superclasses of
631  * <i>obj</i> or modules included in <i>obj</i>.
632  *
633  * module M; end
634  * class A
635  * include M
636  * end
637  * class B < A; end
638  * class C < B; end
639  *
640  * b = B.new
641  * b.is_a? A #=> true
642  * b.is_a? B #=> true
643  * b.is_a? C #=> false
644  * b.is_a? M #=> true
645  *
646  * b.kind_of? A #=> true
647  * b.kind_of? B #=> true
648  * b.kind_of? C #=> false
649  * b.kind_of? M #=> true
650  */
651 
652 VALUE
654 {
655  VALUE cl = CLASS_OF(obj);
656 
658  return class_search_ancestor(cl, RCLASS_ORIGIN(c)) ? Qtrue : Qfalse;
659 }
660 
661 static VALUE
663 {
664  while (cl) {
665  if (cl == c || RCLASS_M_TBL_WRAPPER(cl) == RCLASS_M_TBL_WRAPPER(c))
666  return cl;
667  cl = RCLASS_SUPER(cl);
668  }
669  return 0;
670 }
671 
672 VALUE
674 {
675  cl = class_or_module_required(cl);
677  return class_search_ancestor(cl, RCLASS_ORIGIN(c));
678 }
679 
680 /*
681  * call-seq:
682  * obj.tap{|x|...} -> obj
683  *
684  * Yields <code>x</code> to the block, and then returns <code>x</code>.
685  * The primary purpose of this method is to "tap into" a method chain,
686  * in order to perform operations on intermediate results within the chain.
687  *
688  * (1..10) .tap {|x| puts "original: #{x.inspect}"}
689  * .to_a .tap {|x| puts "array: #{x.inspect}"}
690  * .select {|x| x%2==0} .tap {|x| puts "evens: #{x.inspect}"}
691  * .map { |x| x*x } .tap {|x| puts "squares: #{x.inspect}"}
692  *
693  */
694 
695 VALUE
697 {
698  rb_yield(obj);
699  return obj;
700 }
701 
702 
703 /*
704  * Document-method: inherited
705  *
706  * call-seq:
707  * inherited(subclass)
708  *
709  * Callback invoked whenever a subclass of the current class is created.
710  *
711  * Example:
712  *
713  * class Foo
714  * def self.inherited(subclass)
715  * puts "New subclass: #{subclass}"
716  * end
717  * end
718  *
719  * class Bar < Foo
720  * end
721  *
722  * class Baz < Bar
723  * end
724  *
725  * produces:
726  *
727  * New subclass: Bar
728  * New subclass: Baz
729  */
730 
731 /* Document-method: method_added
732  *
733  * call-seq:
734  * method_added(method_name)
735  *
736  * Invoked as a callback whenever an instance method is added to the
737  * receiver.
738  *
739  * module Chatty
740  * def self.method_added(method_name)
741  * puts "Adding #{method_name.inspect}"
742  * end
743  * def self.some_class_method() end
744  * def some_instance_method() end
745  * end
746  *
747  * produces:
748  *
749  * Adding :some_instance_method
750  *
751  */
752 
753 /* Document-method: method_removed
754  *
755  * call-seq:
756  * method_removed(method_name)
757  *
758  * Invoked as a callback whenever an instance method is removed from the
759  * receiver.
760  *
761  * module Chatty
762  * def self.method_removed(method_name)
763  * puts "Removing #{method_name.inspect}"
764  * end
765  * def self.some_class_method() end
766  * def some_instance_method() end
767  * class << self
768  * remove_method :some_class_method
769  * end
770  * remove_method :some_instance_method
771  * end
772  *
773  * produces:
774  *
775  * Removing :some_instance_method
776  *
777  */
778 
779 /*
780  * Document-method: singleton_method_added
781  *
782  * call-seq:
783  * singleton_method_added(symbol)
784  *
785  * Invoked as a callback whenever a singleton method is added to the
786  * receiver.
787  *
788  * module Chatty
789  * def Chatty.singleton_method_added(id)
790  * puts "Adding #{id.id2name}"
791  * end
792  * def self.one() end
793  * def two() end
794  * def Chatty.three() end
795  * end
796  *
797  * <em>produces:</em>
798  *
799  * Adding singleton_method_added
800  * Adding one
801  * Adding three
802  *
803  */
804 
805 /*
806  * Document-method: singleton_method_removed
807  *
808  * call-seq:
809  * singleton_method_removed(symbol)
810  *
811  * Invoked as a callback whenever a singleton method is removed from
812  * the receiver.
813  *
814  * module Chatty
815  * def Chatty.singleton_method_removed(id)
816  * puts "Removing #{id.id2name}"
817  * end
818  * def self.one() end
819  * def two() end
820  * def Chatty.three() end
821  * class << self
822  * remove_method :three
823  * remove_method :one
824  * end
825  * end
826  *
827  * <em>produces:</em>
828  *
829  * Removing three
830  * Removing one
831  */
832 
833 /*
834  * Document-method: singleton_method_undefined
835  *
836  * call-seq:
837  * singleton_method_undefined(symbol)
838  *
839  * Invoked as a callback whenever a singleton method is undefined in
840  * the receiver.
841  *
842  * module Chatty
843  * def Chatty.singleton_method_undefined(id)
844  * puts "Undefining #{id.id2name}"
845  * end
846  * def Chatty.one() end
847  * class << self
848  * undef_method(:one)
849  * end
850  * end
851  *
852  * <em>produces:</em>
853  *
854  * Undefining one
855  */
856 
857 /*
858  * Document-method: extended
859  *
860  * call-seq:
861  * extended(othermod)
862  *
863  * The equivalent of <tt>included</tt>, but for extended modules.
864  *
865  * module A
866  * def self.extended(mod)
867  * puts "#{self} extended in #{mod}"
868  * end
869  * end
870  * module Enumerable
871  * extend A
872  * end
873  * # => prints "A extended in Enumerable"
874  */
875 
876 /*
877  * Document-method: included
878  *
879  * call-seq:
880  * included(othermod)
881  *
882  * Callback invoked whenever the receiver is included in another
883  * module or class. This should be used in preference to
884  * <tt>Module.append_features</tt> if your code wants to perform some
885  * action when a module is included in another.
886  *
887  * module A
888  * def A.included(mod)
889  * puts "#{self} included in #{mod}"
890  * end
891  * end
892  * module Enumerable
893  * include A
894  * end
895  * # => prints "A included in Enumerable"
896  */
897 
898 /*
899  * Document-method: prepended
900  *
901  * call-seq:
902  * prepended(othermod)
903  *
904  * The equivalent of <tt>included</tt>, but for prepended modules.
905  *
906  * module A
907  * def self.prepended(mod)
908  * puts "#{self} prepended to #{mod}"
909  * end
910  * end
911  * module Enumerable
912  * prepend A
913  * end
914  * # => prints "A prepended to Enumerable"
915  */
916 
917 /*
918  * Document-method: initialize
919  *
920  * call-seq:
921  * BasicObject.new
922  *
923  * Returns a new BasicObject.
924  */
925 
926 /*
927  * Not documented
928  */
929 
930 static VALUE
932 {
933  return Qnil;
934 }
935 
936 /*
937  * call-seq:
938  * obj.tainted? -> true or false
939  *
940  * Returns true if the object is tainted.
941  *
942  * See #taint for more information.
943  */
944 
945 VALUE
947 {
948  if (OBJ_TAINTED(obj))
949  return Qtrue;
950  return Qfalse;
951 }
952 
953 /*
954  * call-seq:
955  * obj.taint -> obj
956  *
957  * Mark the object as tainted.
958  *
959  * Objects that are marked as tainted will be restricted from various built-in
960  * methods. This is to prevent insecure data, such as command-line arguments
961  * or strings read from Kernel#gets, from inadvertently compromising the users
962  * system.
963  *
964  * To check whether an object is tainted, use #tainted?
965  *
966  * You should only untaint a tainted object if your code has inspected it and
967  * determined that it is safe. To do so use #untaint
968  *
969  * In $SAFE level 3, all newly created objects are tainted and you can't untaint
970  * objects.
971  */
972 
973 VALUE
975 {
976  if (!OBJ_TAINTED(obj)) {
977  rb_check_frozen(obj);
978  OBJ_TAINT(obj);
979  }
980  return obj;
981 }
982 
983 
984 /*
985  * call-seq:
986  * obj.untaint -> obj
987  *
988  * Removes the tainted mark from the object.
989  *
990  * See #taint for more information.
991  */
992 
993 VALUE
995 {
996  rb_secure(3);
997  if (OBJ_TAINTED(obj)) {
998  rb_check_frozen(obj);
999  FL_UNSET(obj, FL_TAINT);
1000  }
1001  return obj;
1002 }
1003 
1004 /*
1005  * call-seq:
1006  * obj.untrusted? -> true or false
1007  *
1008  * Deprecated method that is equivalent to #tainted?.
1009  */
1010 
1011 VALUE
1013 {
1014  rb_warning("untrusted? is deprecated and its behavior is same as tainted?");
1015  return rb_obj_tainted(obj);
1016 }
1017 
1018 /*
1019  * call-seq:
1020  * obj.untrust -> obj
1021  *
1022  * Deprecated method that is equivalent to #taint.
1023  */
1024 
1025 VALUE
1027 {
1028  rb_warning("untrust is deprecated and its behavior is same as taint");
1029  return rb_obj_taint(obj);
1030 }
1031 
1032 
1033 /*
1034  * call-seq:
1035  * obj.trust -> obj
1036  *
1037  * Deprecated method that is equivalent to #untaint.
1038  */
1039 
1040 VALUE
1042 {
1043  rb_warning("trust is deprecated and its behavior is same as untaint");
1044  return rb_obj_untaint(obj);
1045 }
1046 
1047 void
1049 {
1050  OBJ_INFECT(obj1, obj2);
1051 }
1052 
1054 
1055 /*
1056  * call-seq:
1057  * obj.freeze -> obj
1058  *
1059  * Prevents further modifications to <i>obj</i>. A
1060  * <code>RuntimeError</code> will be raised if modification is attempted.
1061  * There is no way to unfreeze a frozen object. See also
1062  * <code>Object#frozen?</code>.
1063  *
1064  * This method returns self.
1065  *
1066  * a = [ "a", "b", "c" ]
1067  * a.freeze
1068  * a << "z"
1069  *
1070  * <em>produces:</em>
1071  *
1072  * prog.rb:3:in `<<': can't modify frozen array (RuntimeError)
1073  * from prog.rb:3
1074  */
1075 
1076 VALUE
1078 {
1079  if (!OBJ_FROZEN(obj)) {
1080  OBJ_FREEZE(obj);
1081  if (SPECIAL_CONST_P(obj)) {
1082  if (!immediate_frozen_tbl) {
1083  immediate_frozen_tbl = st_init_numtable();
1084  }
1085  st_insert(immediate_frozen_tbl, obj, (st_data_t)Qtrue);
1086  }
1087  }
1088  return obj;
1089 }
1090 
1091 /*
1092  * call-seq:
1093  * obj.frozen? -> true or false
1094  *
1095  * Returns the freeze status of <i>obj</i>.
1096  *
1097  * a = [ "a", "b", "c" ]
1098  * a.freeze #=> ["a", "b", "c"]
1099  * a.frozen? #=> true
1100  */
1101 
1102 VALUE
1104 {
1105  if (OBJ_FROZEN(obj)) return Qtrue;
1106  if (SPECIAL_CONST_P(obj)) {
1107  if (!immediate_frozen_tbl) return Qfalse;
1108  if (st_lookup(immediate_frozen_tbl, obj, 0)) return Qtrue;
1109  }
1110  return Qfalse;
1111 }
1112 
1113 
1114 /*
1115  * Document-class: NilClass
1116  *
1117  * The class of the singleton object <code>nil</code>.
1118  */
1119 
1120 /*
1121  * call-seq:
1122  * nil.to_i -> 0
1123  *
1124  * Always returns zero.
1125  *
1126  * nil.to_i #=> 0
1127  */
1128 
1129 
1130 static VALUE
1132 {
1133  return INT2FIX(0);
1134 }
1135 
1136 /*
1137  * call-seq:
1138  * nil.to_f -> 0.0
1139  *
1140  * Always returns zero.
1141  *
1142  * nil.to_f #=> 0.0
1143  */
1144 
1145 static VALUE
1147 {
1148  return DBL2NUM(0.0);
1149 }
1150 
1151 /*
1152  * call-seq:
1153  * nil.to_s -> ""
1154  *
1155  * Always returns the empty string.
1156  */
1157 
1158 static VALUE
1160 {
1161  return rb_usascii_str_new(0, 0);
1162 }
1163 
1164 /*
1165  * Document-method: to_a
1166  *
1167  * call-seq:
1168  * nil.to_a -> []
1169  *
1170  * Always returns an empty array.
1171  *
1172  * nil.to_a #=> []
1173  */
1174 
1175 static VALUE
1177 {
1178  return rb_ary_new2(0);
1179 }
1180 
1181 /*
1182  * Document-method: to_h
1183  *
1184  * call-seq:
1185  * nil.to_h -> {}
1186  *
1187  * Always returns an empty hash.
1188  *
1189  * nil.to_h #=> {}
1190  */
1191 
1192 static VALUE
1194 {
1195  return rb_hash_new();
1196 }
1197 
1198 /*
1199  * call-seq:
1200  * nil.inspect -> "nil"
1201  *
1202  * Always returns the string "nil".
1203  */
1204 
1205 static VALUE
1207 {
1208  return rb_usascii_str_new2("nil");
1209 }
1210 
1211 /***********************************************************************
1212  * Document-class: TrueClass
1213  *
1214  * The global value <code>true</code> is the only instance of class
1215  * <code>TrueClass</code> and represents a logically true value in
1216  * boolean expressions. The class provides operators allowing
1217  * <code>true</code> to be used in logical expressions.
1218  */
1219 
1220 
1221 /*
1222  * call-seq:
1223  * true.to_s -> "true"
1224  *
1225  * The string representation of <code>true</code> is "true".
1226  */
1227 
1228 static VALUE
1230 {
1231  return rb_usascii_str_new2("true");
1232 }
1233 
1234 
1235 /*
1236  * call-seq:
1237  * true & obj -> true or false
1238  *
1239  * And---Returns <code>false</code> if <i>obj</i> is
1240  * <code>nil</code> or <code>false</code>, <code>true</code> otherwise.
1241  */
1242 
1243 static VALUE
1245 {
1246  return RTEST(obj2)?Qtrue:Qfalse;
1247 }
1248 
1249 /*
1250  * call-seq:
1251  * true | obj -> true
1252  *
1253  * Or---Returns <code>true</code>. As <i>anObject</i> is an argument to
1254  * a method call, it is always evaluated; there is no short-circuit
1255  * evaluation in this case.
1256  *
1257  * true | puts("or")
1258  * true || puts("logical or")
1259  *
1260  * <em>produces:</em>
1261  *
1262  * or
1263  */
1264 
1265 static VALUE
1266 true_or(VALUE obj, VALUE obj2)
1267 {
1268  return Qtrue;
1269 }
1270 
1271 
1272 /*
1273  * call-seq:
1274  * true ^ obj -> !obj
1275  *
1276  * Exclusive Or---Returns <code>true</code> if <i>obj</i> is
1277  * <code>nil</code> or <code>false</code>, <code>false</code>
1278  * otherwise.
1279  */
1280 
1281 static VALUE
1283 {
1284  return RTEST(obj2)?Qfalse:Qtrue;
1285 }
1286 
1287 
1288 /*
1289  * Document-class: FalseClass
1290  *
1291  * The global value <code>false</code> is the only instance of class
1292  * <code>FalseClass</code> and represents a logically false value in
1293  * boolean expressions. The class provides operators allowing
1294  * <code>false</code> to participate correctly in logical expressions.
1295  *
1296  */
1297 
1298 /*
1299  * call-seq:
1300  * false.to_s -> "false"
1301  *
1302  * 'nuf said...
1303  */
1304 
1305 static VALUE
1307 {
1308  return rb_usascii_str_new2("false");
1309 }
1310 
1311 /*
1312  * call-seq:
1313  * false & obj -> false
1314  * nil & obj -> false
1315  *
1316  * And---Returns <code>false</code>. <i>obj</i> is always
1317  * evaluated as it is the argument to a method call---there is no
1318  * short-circuit evaluation in this case.
1319  */
1320 
1321 static VALUE
1323 {
1324  return Qfalse;
1325 }
1326 
1327 
1328 /*
1329  * call-seq:
1330  * false | obj -> true or false
1331  * nil | obj -> true or false
1332  *
1333  * Or---Returns <code>false</code> if <i>obj</i> is
1334  * <code>nil</code> or <code>false</code>; <code>true</code> otherwise.
1335  */
1336 
1337 static VALUE
1339 {
1340  return RTEST(obj2)?Qtrue:Qfalse;
1341 }
1342 
1343 
1344 
1345 /*
1346  * call-seq:
1347  * false ^ obj -> true or false
1348  * nil ^ obj -> true or false
1349  *
1350  * Exclusive Or---If <i>obj</i> is <code>nil</code> or
1351  * <code>false</code>, returns <code>false</code>; otherwise, returns
1352  * <code>true</code>.
1353  *
1354  */
1355 
1356 static VALUE
1358 {
1359  return RTEST(obj2)?Qtrue:Qfalse;
1360 }
1361 
1362 /*
1363  * call-seq:
1364  * nil.nil? -> true
1365  *
1366  * Only the object <i>nil</i> responds <code>true</code> to <code>nil?</code>.
1367  */
1368 
1369 static VALUE
1371 {
1372  return Qtrue;
1373 }
1374 
1375 /*
1376  * call-seq:
1377  * nil.nil? -> true
1378  * <anything_else>.nil? -> false
1379  *
1380  * Only the object <i>nil</i> responds <code>true</code> to <code>nil?</code>.
1381  */
1382 
1383 
1384 static VALUE
1386 {
1387  return Qfalse;
1388 }
1389 
1390 
1391 /*
1392  * call-seq:
1393  * obj =~ other -> nil
1394  *
1395  * Pattern Match---Overridden by descendants (notably
1396  * <code>Regexp</code> and <code>String</code>) to provide meaningful
1397  * pattern-match semantics.
1398  */
1399 
1400 static VALUE
1402 {
1403  return Qnil;
1404 }
1405 
1406 /*
1407  * call-seq:
1408  * obj !~ other -> true or false
1409  *
1410  * Returns true if two objects do not match (using the <i>=~</i>
1411  * method), otherwise false.
1412  */
1413 
1414 static VALUE
1416 {
1417  VALUE result = rb_funcall(obj1, id_match, 1, obj2);
1418  return RTEST(result) ? Qfalse : Qtrue;
1419 }
1420 
1421 
1422 /*
1423  * call-seq:
1424  * obj <=> other -> 0 or nil
1425  *
1426  * Returns 0 if +obj+ and +other+ are the same object
1427  * or <code>obj == other</code>, otherwise nil.
1428  *
1429  * The <=> is used by various methods to compare objects, for example
1430  * Enumerable#sort, Enumerable#max etc.
1431  *
1432  * Your implementation of <=> should return one of the following values: -1, 0,
1433  * 1 or nil. -1 means self is smaller than other. 0 means self is equal to other.
1434  * 1 means self is bigger than other. Nil means the two values could not be
1435  * compared.
1436  *
1437  * When you define <=>, you can include Comparable to gain the methods <=, <,
1438  * ==, >=, > and between?.
1439  */
1440 static VALUE
1442 {
1443  if (obj1 == obj2 || rb_equal(obj1, obj2))
1444  return INT2FIX(0);
1445  return Qnil;
1446 }
1447 
1448 /***********************************************************************
1449  *
1450  * Document-class: Module
1451  *
1452  * A <code>Module</code> is a collection of methods and constants. The
1453  * methods in a module may be instance methods or module methods.
1454  * Instance methods appear as methods in a class when the module is
1455  * included, module methods do not. Conversely, module methods may be
1456  * called without creating an encapsulating object, while instance
1457  * methods may not. (See <code>Module#module_function</code>)
1458  *
1459  * In the descriptions that follow, the parameter <i>sym</i> refers
1460  * to a symbol, which is either a quoted string or a
1461  * <code>Symbol</code> (such as <code>:name</code>).
1462  *
1463  * module Mod
1464  * include Math
1465  * CONST = 1
1466  * def meth
1467  * # ...
1468  * end
1469  * end
1470  * Mod.class #=> Module
1471  * Mod.constants #=> [:CONST, :PI, :E]
1472  * Mod.instance_methods #=> [:meth]
1473  *
1474  */
1475 
1476 /*
1477  * call-seq:
1478  * mod.to_s -> string
1479  *
1480  * Return a string representing this module or class. For basic
1481  * classes and modules, this is the name. For singletons, we
1482  * show information on the thing we're attached to as well.
1483  */
1484 
1485 static VALUE
1487 {
1488  ID id_defined_at;
1489  VALUE refined_class, defined_at;
1490 
1491  if (FL_TEST(klass, FL_SINGLETON)) {
1492  VALUE s = rb_usascii_str_new2("#<Class:");
1493  VALUE v = rb_ivar_get(klass, id__attached__);
1494 
1495  if (CLASS_OR_MODULE_P(v)) {
1496  rb_str_append(s, rb_inspect(v));
1497  }
1498  else {
1499  rb_str_append(s, rb_any_to_s(v));
1500  }
1501  rb_str_cat2(s, ">");
1502 
1503  return s;
1504  }
1505  refined_class = rb_refinement_module_get_refined_class(klass);
1506  if (!NIL_P(refined_class)) {
1507  VALUE s = rb_usascii_str_new2("#<refinement:");
1508 
1509  rb_str_concat(s, rb_inspect(refined_class));
1510  rb_str_cat2(s, "@");
1511  CONST_ID(id_defined_at, "__defined_at__");
1512  defined_at = rb_attr_get(klass, id_defined_at);
1513  rb_str_concat(s, rb_inspect(defined_at));
1514  rb_str_cat2(s, ">");
1515  return s;
1516  }
1517  return rb_str_dup(rb_class_name(klass));
1518 }
1519 
1520 /*
1521  * call-seq:
1522  * mod.freeze -> mod
1523  *
1524  * Prevents further modifications to <i>mod</i>.
1525  *
1526  * This method returns self.
1527  */
1528 
1529 static VALUE
1531 {
1532  rb_class_name(mod);
1533  return rb_obj_freeze(mod);
1534 }
1535 
1536 /*
1537  * call-seq:
1538  * mod === obj -> true or false
1539  *
1540  * Case Equality---Returns <code>true</code> if <i>anObject</i> is an
1541  * instance of <i>mod</i> or one of <i>mod</i>'s descendants. Of
1542  * limited use for modules, but can be used in <code>case</code>
1543  * statements to classify objects by class.
1544  */
1545 
1546 static VALUE
1548 {
1549  return rb_obj_is_kind_of(arg, mod);
1550 }
1551 
1552 /*
1553  * call-seq:
1554  * mod <= other -> true, false, or nil
1555  *
1556  * Returns true if <i>mod</i> is a subclass of <i>other</i> or
1557  * is the same as <i>other</i>. Returns
1558  * <code>nil</code> if there's no relationship between the two.
1559  * (Think of the relationship in terms of the class definition:
1560  * "class A<B" implies "A<B").
1561  *
1562  */
1563 
1564 VALUE
1566 {
1567  VALUE start = mod;
1568 
1569  if (mod == arg) return Qtrue;
1570  if (!CLASS_OR_MODULE_P(arg) && !RB_TYPE_P(arg, T_ICLASS)) {
1571  rb_raise(rb_eTypeError, "compared with non class/module");
1572  }
1573  arg = RCLASS_ORIGIN(arg);
1574  if (class_search_ancestor(mod, arg)) {
1575  return Qtrue;
1576  }
1577  /* not mod < arg; check if mod > arg */
1578  if (class_search_ancestor(arg, start)) {
1579  return Qfalse;
1580  }
1581  return Qnil;
1582 }
1583 
1584 /*
1585  * call-seq:
1586  * mod < other -> true, false, or nil
1587  *
1588  * Returns true if <i>mod</i> is a subclass of <i>other</i>. Returns
1589  * <code>nil</code> if there's no relationship between the two.
1590  * (Think of the relationship in terms of the class definition:
1591  * "class A<B" implies "A<B").
1592  *
1593  */
1594 
1595 static VALUE
1597 {
1598  if (mod == arg) return Qfalse;
1599  return rb_class_inherited_p(mod, arg);
1600 }
1601 
1602 
1603 /*
1604  * call-seq:
1605  * mod >= other -> true, false, or nil
1606  *
1607  * Returns true if <i>mod</i> is an ancestor of <i>other</i>, or the
1608  * two modules are the same. Returns
1609  * <code>nil</code> if there's no relationship between the two.
1610  * (Think of the relationship in terms of the class definition:
1611  * "class A<B" implies "B>A").
1612  *
1613  */
1614 
1615 static VALUE
1617 {
1618  if (!CLASS_OR_MODULE_P(arg)) {
1619  rb_raise(rb_eTypeError, "compared with non class/module");
1620  }
1621 
1622  return rb_class_inherited_p(arg, mod);
1623 }
1624 
1625 /*
1626  * call-seq:
1627  * mod > other -> true, false, or nil
1628  *
1629  * Returns true if <i>mod</i> is an ancestor of <i>other</i>. Returns
1630  * <code>nil</code> if there's no relationship between the two.
1631  * (Think of the relationship in terms of the class definition:
1632  * "class A<B" implies "B>A").
1633  *
1634  */
1635 
1636 static VALUE
1638 {
1639  if (mod == arg) return Qfalse;
1640  return rb_mod_ge(mod, arg);
1641 }
1642 
1643 /*
1644  * call-seq:
1645  * module <=> other_module -> -1, 0, +1, or nil
1646  *
1647  * Comparison---Returns -1, 0, +1 or nil depending on whether +module+
1648  * includes +other_module+, they are the same, or if +module+ is included by
1649  * +other_module+. This is the basis for the tests in Comparable.
1650  *
1651  * Returns +nil+ if +module+ has no relationship with +other_module+, if
1652  * +other_module+ is not a module, or if the two values are incomparable.
1653  */
1654 
1655 static VALUE
1657 {
1658  VALUE cmp;
1659 
1660  if (mod == arg) return INT2FIX(0);
1661  if (!CLASS_OR_MODULE_P(arg)) {
1662  return Qnil;
1663  }
1664 
1665  cmp = rb_class_inherited_p(mod, arg);
1666  if (NIL_P(cmp)) return Qnil;
1667  if (cmp) {
1668  return INT2FIX(-1);
1669  }
1670  return INT2FIX(1);
1671 }
1672 
1673 static VALUE
1675 {
1676  VALUE mod = rb_module_new();
1677 
1678  RBASIC_SET_CLASS(mod, klass);
1679  return mod;
1680 }
1681 
1682 static VALUE
1684 {
1685  return rb_class_boot(0);
1686 }
1687 
1688 /*
1689  * call-seq:
1690  * Module.new -> mod
1691  * Module.new {|mod| block } -> mod
1692  *
1693  * Creates a new anonymous module. If a block is given, it is passed
1694  * the module object, and the block is evaluated in the context of this
1695  * module using <code>module_eval</code>.
1696  *
1697  * fred = Module.new do
1698  * def meth1
1699  * "hello"
1700  * end
1701  * def meth2
1702  * "bye"
1703  * end
1704  * end
1705  * a = "my string"
1706  * a.extend(fred) #=> "my string"
1707  * a.meth1 #=> "hello"
1708  * a.meth2 #=> "bye"
1709  *
1710  * Assign the module to a constant (name starting uppercase) if you
1711  * want to treat it like a regular module.
1712  */
1713 
1714 static VALUE
1716 {
1717  if (rb_block_given_p()) {
1718  rb_mod_module_exec(1, &module, module);
1719  }
1720  return Qnil;
1721 }
1722 
1723 /*
1724  * call-seq:
1725  * Class.new(super_class=Object) -> a_class
1726  * Class.new(super_class=Object) { |mod| ... } -> a_class
1727  *
1728  * Creates a new anonymous (unnamed) class with the given superclass
1729  * (or <code>Object</code> if no parameter is given). You can give a
1730  * class a name by assigning the class object to a constant.
1731  *
1732  * If a block is given, it is passed the class object, and the block
1733  * is evaluated in the context of this class using
1734  * <code>class_eval</code>.
1735  *
1736  * fred = Class.new do
1737  * def meth1
1738  * "hello"
1739  * end
1740  * def meth2
1741  * "bye"
1742  * end
1743  * end
1744  *
1745  * a = fred.new #=> #<#<Class:0x100381890>:0x100376b98>
1746  * a.meth1 #=> "hello"
1747  * a.meth2 #=> "bye"
1748  *
1749  * Assign the class to a constant (name starting uppercase) if you
1750  * want to treat it like a regular class.
1751  */
1752 
1753 static VALUE
1755 {
1756  VALUE super;
1757 
1758  if (RCLASS_SUPER(klass) != 0 || klass == rb_cBasicObject) {
1759  rb_raise(rb_eTypeError, "already initialized class");
1760  }
1761  if (argc == 0) {
1762  super = rb_cObject;
1763  }
1764  else {
1765  rb_scan_args(argc, argv, "01", &super);
1766  rb_check_inheritable(super);
1767  if (super != rb_cBasicObject && !RCLASS_SUPER(super)) {
1768  rb_raise(rb_eTypeError, "can't inherit uninitialized class");
1769  }
1770  }
1771  RCLASS_SET_SUPER(klass, super);
1772  rb_make_metaclass(klass, RBASIC(super)->klass);
1773  rb_class_inherited(super, klass);
1774  rb_mod_initialize(klass);
1775 
1776  return klass;
1777 }
1778 
1779 /*
1780  * call-seq:
1781  * class.allocate() -> obj
1782  *
1783  * Allocates space for a new object of <i>class</i>'s class and does not
1784  * call initialize on the new instance. The returned object must be an
1785  * instance of <i>class</i>.
1786  *
1787  * klass = Class.new do
1788  * def initialize(*args)
1789  * @initialized = true
1790  * end
1791  *
1792  * def initialized?
1793  * @initialized || false
1794  * end
1795  * end
1796  *
1797  * klass.allocate.initialized? #=> false
1798  *
1799  */
1800 
1801 VALUE
1803 {
1804  VALUE obj;
1805  rb_alloc_func_t allocator;
1806 
1807  if (RCLASS_SUPER(klass) == 0 && klass != rb_cBasicObject) {
1808  rb_raise(rb_eTypeError, "can't instantiate uninitialized class");
1809  }
1810  if (FL_TEST(klass, FL_SINGLETON)) {
1811  rb_raise(rb_eTypeError, "can't create instance of singleton class");
1812  }
1813  allocator = rb_get_alloc_func(klass);
1814  if (!allocator) {
1815  rb_raise(rb_eTypeError, "allocator undefined for %"PRIsVALUE,
1816  klass);
1817  }
1818 
1819 #if !defined(DTRACE_PROBES_DISABLED) || !DTRACE_PROBES_DISABLED
1821  const char * file = rb_sourcefile();
1823  file ? file : "",
1824  rb_sourceline());
1825  }
1826 #endif
1827 
1828  obj = (*allocator)(klass);
1829 
1830  if (rb_obj_class(obj) != rb_class_real(klass)) {
1831  rb_raise(rb_eTypeError, "wrong instance allocation");
1832  }
1833  return obj;
1834 }
1835 
1836 static VALUE
1838 {
1839  NEWOBJ_OF(obj, struct RObject, klass, T_OBJECT | (RGENGC_WB_PROTECTED_OBJECT ? FL_WB_PROTECTED : 0));
1840  return (VALUE)obj;
1841 }
1842 
1843 /*
1844  * call-seq:
1845  * class.new(args, ...) -> obj
1846  *
1847  * Calls <code>allocate</code> to create a new object of
1848  * <i>class</i>'s class, then invokes that object's
1849  * <code>initialize</code> method, passing it <i>args</i>.
1850  * This is the method that ends up getting called whenever
1851  * an object is constructed using .new.
1852  *
1853  */
1854 
1855 VALUE
1857 {
1858  VALUE obj;
1859 
1860  obj = rb_obj_alloc(klass);
1861  rb_obj_call_init(obj, argc, argv);
1862 
1863  return obj;
1864 }
1865 
1866 /*
1867  * call-seq:
1868  * class.superclass -> a_super_class or nil
1869  *
1870  * Returns the superclass of <i>class</i>, or <code>nil</code>.
1871  *
1872  * File.superclass #=> IO
1873  * IO.superclass #=> Object
1874  * Object.superclass #=> BasicObject
1875  * class Foo; end
1876  * class Bar < Foo; end
1877  * Bar.superclass #=> Foo
1878  *
1879  * returns nil when the given class hasn't a parent class:
1880  *
1881  * BasicObject.superclass #=> nil
1882  *
1883  */
1884 
1885 VALUE
1887 {
1888  VALUE super = RCLASS_SUPER(klass);
1889 
1890  if (!super) {
1891  if (klass == rb_cBasicObject) return Qnil;
1892  rb_raise(rb_eTypeError, "uninitialized class");
1893  }
1894  while (RB_TYPE_P(super, T_ICLASS)) {
1895  super = RCLASS_SUPER(super);
1896  }
1897  if (!super) {
1898  return Qnil;
1899  }
1900  return super;
1901 }
1902 
1903 VALUE
1905 {
1906  return RCLASS(klass)->super;
1907 }
1908 
1909 #define id_for_setter(name, type, message) \
1910  check_setter_id(name, rb_is_##type##_id, rb_is_##type##_name, message)
1911 static ID
1912 check_setter_id(VALUE name, int (*valid_id_p)(ID), int (*valid_name_p)(VALUE),
1913  const char *message)
1914 {
1915  ID id;
1916  if (SYMBOL_P(name)) {
1917  id = SYM2ID(name);
1918  if (!valid_id_p(id)) {
1919  rb_name_error(id, message, QUOTE_ID(id));
1920  }
1921  }
1922  else {
1923  VALUE str = rb_check_string_type(name);
1924  if (NIL_P(str)) {
1925  rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol or string",
1926  str);
1927  }
1928  if (!valid_name_p(str)) {
1929  rb_name_error_str(str, message, QUOTE(str));
1930  }
1931  id = rb_to_id(str);
1932  }
1933  return id;
1934 }
1935 
1936 static int
1938 {
1939  return rb_is_local_id(id) || rb_is_const_id(id);
1940 }
1941 
1942 static int
1944 {
1945  return rb_is_local_name(name) || rb_is_const_name(name);
1946 }
1947 
1948 static const char invalid_attribute_name[] = "invalid attribute name `%"PRIsVALUE"'";
1949 
1950 static ID
1952 {
1953  return id_for_setter(name, attr, invalid_attribute_name);
1954 }
1955 
1956 ID
1958 {
1959  if (!rb_is_attr_id(id)) {
1960  rb_name_error_str(id, invalid_attribute_name, QUOTE_ID(id));
1961  }
1962  return id;
1963 }
1964 
1965 /*
1966  * call-seq:
1967  * attr_reader(symbol, ...) -> nil
1968  * attr(symbol, ...) -> nil
1969  * attr_reader(string, ...) -> nil
1970  * attr(string, ...) -> nil
1971  *
1972  * Creates instance variables and corresponding methods that return the
1973  * value of each instance variable. Equivalent to calling
1974  * ``<code>attr</code><i>:name</i>'' on each name in turn.
1975  * String arguments are converted to symbols.
1976  */
1977 
1978 static VALUE
1980 {
1981  int i;
1982 
1983  for (i=0; i<argc; i++) {
1984  rb_attr(klass, id_for_attr(argv[i]), TRUE, FALSE, TRUE);
1985  }
1986  return Qnil;
1987 }
1988 
1989 VALUE
1991 {
1992  if (argc == 2 && (argv[1] == Qtrue || argv[1] == Qfalse)) {
1993  rb_warning("optional boolean argument is obsoleted");
1994  rb_attr(klass, id_for_attr(argv[0]), 1, RTEST(argv[1]), TRUE);
1995  return Qnil;
1996  }
1997  return rb_mod_attr_reader(argc, argv, klass);
1998 }
1999 
2000 /*
2001  * call-seq:
2002  * attr_writer(symbol, ...) -> nil
2003  * attr_writer(string, ...) -> nil
2004  *
2005  * Creates an accessor method to allow assignment to the attribute
2006  * <i>symbol</i><code>.id2name</code>.
2007  * String arguments are converted to symbols.
2008  */
2009 
2010 static VALUE
2012 {
2013  int i;
2014 
2015  for (i=0; i<argc; i++) {
2016  rb_attr(klass, id_for_attr(argv[i]), FALSE, TRUE, TRUE);
2017  }
2018  return Qnil;
2019 }
2020 
2021 /*
2022  * call-seq:
2023  * attr_accessor(symbol, ...) -> nil
2024  * attr_accessor(string, ...) -> nil
2025  *
2026  * Defines a named attribute for this module, where the name is
2027  * <i>symbol.</i><code>id2name</code>, creating an instance variable
2028  * (<code>@name</code>) and a corresponding access method to read it.
2029  * Also creates a method called <code>name=</code> to set the attribute.
2030  * String arguments are converted to symbols.
2031  *
2032  * module Mod
2033  * attr_accessor(:one, :two)
2034  * end
2035  * Mod.instance_methods.sort #=> [:one, :one=, :two, :two=]
2036  */
2037 
2038 static VALUE
2040 {
2041  int i;
2042 
2043  for (i=0; i<argc; i++) {
2044  rb_attr(klass, id_for_attr(argv[i]), TRUE, TRUE, TRUE);
2045  }
2046  return Qnil;
2047 }
2048 
2049 /*
2050  * call-seq:
2051  * mod.const_get(sym, inherit=true) -> obj
2052  * mod.const_get(str, inherit=true) -> obj
2053  *
2054  * Checks for a constant with the given name in <i>mod</i>
2055  * If +inherit+ is set, the lookup will also search
2056  * the ancestors (and +Object+ if <i>mod</i> is a +Module+.)
2057  *
2058  * The value of the constant is returned if a definition is found,
2059  * otherwise a +NameError+ is raised.
2060  *
2061  * Math.const_get(:PI) #=> 3.14159265358979
2062  *
2063  * This method will recursively look up constant names if a namespaced
2064  * class name is provided. For example:
2065  *
2066  * module Foo; class Bar; end end
2067  * Object.const_get 'Foo::Bar'
2068  *
2069  * The +inherit+ flag is respected on each lookup. For example:
2070  *
2071  * module Foo
2072  * class Bar
2073  * VAL = 10
2074  * end
2075  *
2076  * class Baz < Bar; end
2077  * end
2078  *
2079  * Object.const_get 'Foo::Baz::VAL' # => 10
2080  * Object.const_get 'Foo::Baz::VAL', false # => NameError
2081  *
2082  * If neither +sym+ nor +str+ is not a valid constant name a NameError will be
2083  * raised with a warning "wrong constant name".
2084  *
2085  * Object.const_get 'foobar' #=> NameError: wrong constant name foobar
2086  *
2087  */
2088 
2089 static VALUE
2091 {
2092  VALUE name, recur;
2093  rb_encoding *enc;
2094  const char *pbeg, *p, *path, *pend;
2095  ID id;
2096 
2097  if (argc == 1) {
2098  name = argv[0];
2099  recur = Qtrue;
2100  }
2101  else {
2102  rb_scan_args(argc, argv, "11", &name, &recur);
2103  }
2104 
2105  if (SYMBOL_P(name)) {
2106  id = SYM2ID(name);
2107  if (!rb_is_const_id(id)) goto wrong_id;
2108  return RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id);
2109  }
2110 
2111  path = StringValuePtr(name);
2112  enc = rb_enc_get(name);
2113 
2114  if (!rb_enc_asciicompat(enc)) {
2115  rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
2116  }
2117 
2118  pbeg = p = path;
2119  pend = path + RSTRING_LEN(name);
2120 
2121  if (p >= pend || !*p) {
2122  wrong_name:
2123  rb_raise(rb_eNameError, "wrong constant name %"PRIsVALUE,
2124  QUOTE(name));
2125  }
2126 
2127  if (p + 2 < pend && p[0] == ':' && p[1] == ':') {
2128  mod = rb_cObject;
2129  p += 2;
2130  pbeg = p;
2131  }
2132 
2133  while (p < pend) {
2134  VALUE part;
2135  long len, beglen;
2136 
2137  while (p < pend && *p != ':') p++;
2138 
2139  if (pbeg == p) goto wrong_name;
2140 
2141  id = rb_check_id_cstr(pbeg, len = p-pbeg, enc);
2142  beglen = pbeg-path;
2143 
2144  if (p < pend && p[0] == ':') {
2145  if (p + 2 >= pend || p[1] != ':') goto wrong_name;
2146  p += 2;
2147  pbeg = p;
2148  }
2149 
2150  if (!RB_TYPE_P(mod, T_MODULE) && !RB_TYPE_P(mod, T_CLASS)) {
2151  rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module",
2152  QUOTE(name));
2153  }
2154 
2155  if (!id) {
2156  part = rb_str_subseq(name, beglen, len);
2157  OBJ_FREEZE(part);
2158  if (!ISUPPER(*pbeg) || !rb_is_const_name(part)) {
2159  rb_name_error_str(part, "wrong constant name %"PRIsVALUE,
2160  QUOTE(part));
2161  }
2163  id = rb_intern_str(part);
2164  }
2165  else {
2166  rb_name_error_str(part, "uninitialized constant %"PRIsVALUE"%"PRIsVALUE,
2167  rb_str_subseq(name, 0, beglen),
2168  QUOTE(part));
2169  }
2170  }
2171  if (!rb_is_const_id(id)) {
2172  wrong_id:
2173  rb_name_error(id, "wrong constant name %"PRIsVALUE,
2174  QUOTE_ID(id));
2175  }
2176  mod = RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id);
2177  }
2178 
2179  return mod;
2180 }
2181 
2182 /*
2183  * call-seq:
2184  * mod.const_set(sym, obj) -> obj
2185  * mod.const_set(str, obj) -> obj
2186  *
2187  * Sets the named constant to the given object, returning that object.
2188  * Creates a new constant if no constant with the given name previously
2189  * existed.
2190  *
2191  * Math.const_set("HIGH_SCHOOL_PI", 22.0/7.0) #=> 3.14285714285714
2192  * Math::HIGH_SCHOOL_PI - Math::PI #=> 0.00126448926734968
2193  *
2194  * If neither +sym+ nor +str+ is not a valid constant name a NameError will be
2195  * raised with a warning "wrong constant name".
2196  *
2197  * Object.const_set('foobar', 42) #=> NameError: wrong constant name foobar
2198  *
2199  */
2200 
2201 static VALUE
2203 {
2204  ID id = id_for_setter(name, const, "wrong constant name %"PRIsVALUE);
2205  rb_const_set(mod, id, value);
2206  return value;
2207 }
2208 
2209 /*
2210  * call-seq:
2211  * mod.const_defined?(sym, inherit=true) -> true or false
2212  * mod.const_defined?(str, inherit=true) -> true or false
2213  *
2214  * Checks for a constant with the given name in <i>mod</i>
2215  * If +inherit+ is set, the lookup will also search
2216  * the ancestors (and +Object+ if <i>mod</i> is a +Module+.)
2217  *
2218  * Returns whether or not a definition is found:
2219  *
2220  * Math.const_defined? "PI" #=> true
2221  * IO.const_defined? :SYNC #=> true
2222  * IO.const_defined? :SYNC, false #=> false
2223  *
2224  * If neither +sym+ nor +str+ is not a valid constant name a NameError will be
2225  * raised with a warning "wrong constant name".
2226  *
2227  * Hash.const_defined? 'foobar' #=> NameError: wrong constant name foobar
2228  *
2229  */
2230 
2231 static VALUE
2233 {
2234  VALUE name, recur;
2235  rb_encoding *enc;
2236  const char *pbeg, *p, *path, *pend;
2237  ID id;
2238 
2239  if (argc == 1) {
2240  name = argv[0];
2241  recur = Qtrue;
2242  }
2243  else {
2244  rb_scan_args(argc, argv, "11", &name, &recur);
2245  }
2246 
2247  if (SYMBOL_P(name)) {
2248  id = SYM2ID(name);
2249  if (!rb_is_const_id(id)) goto wrong_id;
2250  return RTEST(recur) ? rb_const_defined(mod, id) : rb_const_defined_at(mod, id);
2251  }
2252 
2253  path = StringValuePtr(name);
2254  enc = rb_enc_get(name);
2255 
2256  if (!rb_enc_asciicompat(enc)) {
2257  rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
2258  }
2259 
2260  pbeg = p = path;
2261  pend = path + RSTRING_LEN(name);
2262 
2263  if (p >= pend || !*p) {
2264  wrong_name:
2265  rb_raise(rb_eNameError, "wrong constant name %"PRIsVALUE,
2266  QUOTE(name));
2267  }
2268 
2269  if (p + 2 < pend && p[0] == ':' && p[1] == ':') {
2270  mod = rb_cObject;
2271  p += 2;
2272  pbeg = p;
2273  }
2274 
2275  while (p < pend) {
2276  VALUE part;
2277  long len, beglen;
2278 
2279  while (p < pend && *p != ':') p++;
2280 
2281  if (pbeg == p) goto wrong_name;
2282 
2283  id = rb_check_id_cstr(pbeg, len = p-pbeg, enc);
2284  beglen = pbeg-path;
2285 
2286  if (p < pend && p[0] == ':') {
2287  if (p + 2 >= pend || p[1] != ':') goto wrong_name;
2288  p += 2;
2289  pbeg = p;
2290  }
2291 
2292  if (!id) {
2293  part = rb_str_subseq(name, beglen, len);
2294  OBJ_FREEZE(part);
2295  if (!ISUPPER(*pbeg) || !rb_is_const_name(part)) {
2296  rb_name_error_str(part, "wrong constant name %"PRIsVALUE,
2297  QUOTE(part));
2298  }
2299  else {
2300  return Qfalse;
2301  }
2302  }
2303  if (!rb_is_const_id(id)) {
2304  wrong_id:
2305  rb_name_error(id, "wrong constant name %"PRIsVALUE,
2306  QUOTE_ID(id));
2307  }
2308  if (RTEST(recur)) {
2309  if (!rb_const_defined(mod, id))
2310  return Qfalse;
2311  mod = rb_const_get(mod, id);
2312  }
2313  else {
2314  if (!rb_const_defined_at(mod, id))
2315  return Qfalse;
2316  mod = rb_const_get_at(mod, id);
2317  }
2318  recur = Qfalse;
2319 
2320  if (p < pend && !RB_TYPE_P(mod, T_MODULE) && !RB_TYPE_P(mod, T_CLASS)) {
2321  rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module",
2322  QUOTE(name));
2323  }
2324  }
2325 
2326  return Qtrue;
2327 }
2328 
2329 /*
2330  * call-seq:
2331  * obj.instance_variable_get(symbol) -> obj
2332  * obj.instance_variable_get(string) -> obj
2333  *
2334  * Returns the value of the given instance variable, or nil if the
2335  * instance variable is not set. The <code>@</code> part of the
2336  * variable name should be included for regular instance
2337  * variables. Throws a <code>NameError</code> exception if the
2338  * supplied symbol is not valid as an instance variable name.
2339  * String arguments are converted to symbols.
2340  *
2341  * class Fred
2342  * def initialize(p1, p2)
2343  * @a, @b = p1, p2
2344  * end
2345  * end
2346  * fred = Fred.new('cat', 99)
2347  * fred.instance_variable_get(:@a) #=> "cat"
2348  * fred.instance_variable_get("@b") #=> 99
2349  */
2350 
2351 static VALUE
2353 {
2354  ID id = rb_check_id(&iv);
2355 
2356  if (!id) {
2357  if (rb_is_instance_name(iv)) {
2358  return Qnil;
2359  }
2360  else {
2361  rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as an instance variable name",
2362  QUOTE(iv));
2363  }
2364  }
2365  if (!rb_is_instance_id(id)) {
2366  rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an instance variable name",
2367  QUOTE_ID(id));
2368  }
2369  return rb_ivar_get(obj, id);
2370 }
2371 
2372 /*
2373  * call-seq:
2374  * obj.instance_variable_set(symbol, obj) -> obj
2375  * obj.instance_variable_set(string, obj) -> obj
2376  *
2377  * Sets the instance variable names by <i>symbol</i> to
2378  * <i>object</i>, thereby frustrating the efforts of the class's
2379  * author to attempt to provide proper encapsulation. The variable
2380  * did not have to exist prior to this call.
2381  * If the instance variable name is passed as a string, that string
2382  * is converted to a symbol.
2383  *
2384  * class Fred
2385  * def initialize(p1, p2)
2386  * @a, @b = p1, p2
2387  * end
2388  * end
2389  * fred = Fred.new('cat', 99)
2390  * fred.instance_variable_set(:@a, 'dog') #=> "dog"
2391  * fred.instance_variable_set(:@c, 'cat') #=> "cat"
2392  * fred.inspect #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"
2393  */
2394 
2395 static VALUE
2397 {
2398  ID id = id_for_setter(iv, instance, "`%"PRIsVALUE"' is not allowed as an instance variable name");
2399  return rb_ivar_set(obj, id, val);
2400 }
2401 
2402 /*
2403  * call-seq:
2404  * obj.instance_variable_defined?(symbol) -> true or false
2405  * obj.instance_variable_defined?(string) -> true or false
2406  *
2407  * Returns <code>true</code> if the given instance variable is
2408  * defined in <i>obj</i>.
2409  * String arguments are converted to symbols.
2410  *
2411  * class Fred
2412  * def initialize(p1, p2)
2413  * @a, @b = p1, p2
2414  * end
2415  * end
2416  * fred = Fred.new('cat', 99)
2417  * fred.instance_variable_defined?(:@a) #=> true
2418  * fred.instance_variable_defined?("@b") #=> true
2419  * fred.instance_variable_defined?("@c") #=> false
2420  */
2421 
2422 static VALUE
2424 {
2425  ID id = rb_check_id(&iv);
2426 
2427  if (!id) {
2428  if (rb_is_instance_name(iv)) {
2429  return Qfalse;
2430  }
2431  else {
2432  rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as an instance variable name",
2433  QUOTE(iv));
2434  }
2435  }
2436  if (!rb_is_instance_id(id)) {
2437  rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an instance variable name",
2438  QUOTE_ID(id));
2439  }
2440  return rb_ivar_defined(obj, id);
2441 }
2442 
2443 /*
2444  * call-seq:
2445  * mod.class_variable_get(symbol) -> obj
2446  * mod.class_variable_get(string) -> obj
2447  *
2448  * Returns the value of the given class variable (or throws a
2449  * <code>NameError</code> exception). The <code>@@</code> part of the
2450  * variable name should be included for regular class variables
2451  * String arguments are converted to symbols.
2452  *
2453  * class Fred
2454  * @@foo = 99
2455  * end
2456  * Fred.class_variable_get(:@@foo) #=> 99
2457  */
2458 
2459 static VALUE
2461 {
2462  ID id = rb_check_id(&iv);
2463 
2464  if (!id) {
2465  if (rb_is_class_name(iv)) {
2466  rb_name_error_str(iv, "uninitialized class variable %"PRIsVALUE" in %"PRIsVALUE"",
2467  iv, rb_class_name(obj));
2468  }
2469  else {
2470  rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as a class variable name",
2471  QUOTE(iv));
2472  }
2473  }
2474  if (!rb_is_class_id(id)) {
2475  rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a class variable name",
2476  QUOTE_ID(id));
2477  }
2478  return rb_cvar_get(obj, id);
2479 }
2480 
2481 /*
2482  * call-seq:
2483  * obj.class_variable_set(symbol, obj) -> obj
2484  * obj.class_variable_set(string, obj) -> obj
2485  *
2486  * Sets the class variable names by <i>symbol</i> to
2487  * <i>object</i>.
2488  * If the class variable name is passed as a string, that string
2489  * is converted to a symbol.
2490  *
2491  * class Fred
2492  * @@foo = 99
2493  * def foo
2494  * @@foo
2495  * end
2496  * end
2497  * Fred.class_variable_set(:@@foo, 101) #=> 101
2498  * Fred.new.foo #=> 101
2499  */
2500 
2501 static VALUE
2503 {
2504  ID id = id_for_setter(iv, class, "`%"PRIsVALUE"' is not allowed as a class variable name");
2505  rb_cvar_set(obj, id, val);
2506  return val;
2507 }
2508 
2509 /*
2510  * call-seq:
2511  * obj.class_variable_defined?(symbol) -> true or false
2512  * obj.class_variable_defined?(string) -> true or false
2513  *
2514  * Returns <code>true</code> if the given class variable is defined
2515  * in <i>obj</i>.
2516  * String arguments are converted to symbols.
2517  *
2518  * class Fred
2519  * @@foo = 99
2520  * end
2521  * Fred.class_variable_defined?(:@@foo) #=> true
2522  * Fred.class_variable_defined?(:@@bar) #=> false
2523  */
2524 
2525 static VALUE
2527 {
2528  ID id = rb_check_id(&iv);
2529 
2530  if (!id) {
2531  if (rb_is_class_name(iv)) {
2532  return Qfalse;
2533  }
2534  else {
2535  rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as a class variable name",
2536  QUOTE(iv));
2537  }
2538  }
2539  if (!rb_is_class_id(id)) {
2540  rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a class variable name",
2541  QUOTE_ID(id));
2542  }
2543  return rb_cvar_defined(obj, id);
2544 }
2545 
2546 /*
2547  * call-seq:
2548  * mod.singleton_class? -> true or false
2549  *
2550  * Returns <code>true</code> if <i>mod</i> is a singleton class or
2551  * <code>false</code> if it is an ordinary class or module.
2552  *
2553  * class C
2554  * end
2555  * C.singleton_class? #=> false
2556  * C.singleton_class.singleton_class? #=> true
2557  */
2558 
2559 static VALUE
2561 {
2562  if (RB_TYPE_P(klass, T_CLASS) && FL_TEST(klass, FL_SINGLETON))
2563  return Qtrue;
2564  return Qfalse;
2565 }
2566 
2567 static struct conv_method_tbl {
2568  const char *method;
2570 } conv_method_names[] = {
2571  {"to_int", 0},
2572  {"to_ary", 0},
2573  {"to_str", 0},
2574  {"to_sym", 0},
2575  {"to_hash", 0},
2576  {"to_proc", 0},
2577  {"to_io", 0},
2578  {"to_a", 0},
2579  {"to_s", 0},
2580  {NULL, 0}
2581 };
2582 #define IMPLICIT_CONVERSIONS 7
2583 
2584 static VALUE
2585 convert_type(VALUE val, const char *tname, const char *method, int raise)
2586 {
2587  ID m = 0;
2588  int i;
2589  VALUE r;
2590 
2591  for (i=0; conv_method_names[i].method; i++) {
2592  if (conv_method_names[i].method[0] == method[0] &&
2593  strcmp(conv_method_names[i].method, method) == 0) {
2594  m = conv_method_names[i].id;
2595  break;
2596  }
2597  }
2598  if (!m) m = rb_intern(method);
2599  r = rb_check_funcall(val, m, 0, 0);
2600  if (r == Qundef) {
2601  if (raise) {
2603  ? "no implicit conversion of %s into %s"
2604  : "can't convert %s into %s",
2605  NIL_P(val) ? "nil" :
2606  val == Qtrue ? "true" :
2607  val == Qfalse ? "false" :
2608  rb_obj_classname(val),
2609  tname);
2610  }
2611  return Qnil;
2612  }
2613  return r;
2614 }
2615 
2616 VALUE
2617 rb_convert_type(VALUE val, int type, const char *tname, const char *method)
2618 {
2619  VALUE v;
2620 
2621  if (TYPE(val) == type) return val;
2622  v = convert_type(val, tname, method, TRUE);
2623  if (TYPE(v) != type) {
2624  const char *cname = rb_obj_classname(val);
2625  rb_raise(rb_eTypeError, "can't convert %s to %s (%s#%s gives %s)",
2626  cname, tname, cname, method, rb_obj_classname(v));
2627  }
2628  return v;
2629 }
2630 
2631 VALUE
2632 rb_check_convert_type(VALUE val, int type, const char *tname, const char *method)
2633 {
2634  VALUE v;
2635 
2636  /* always convert T_DATA */
2637  if (TYPE(val) == type && type != T_DATA) return val;
2638  v = convert_type(val, tname, method, FALSE);
2639  if (NIL_P(v)) return Qnil;
2640  if (TYPE(v) != type) {
2641  const char *cname = rb_obj_classname(val);
2642  rb_raise(rb_eTypeError, "can't convert %s to %s (%s#%s gives %s)",
2643  cname, tname, cname, method, rb_obj_classname(v));
2644  }
2645  return v;
2646 }
2647 
2648 
2649 static VALUE
2650 rb_to_integer(VALUE val, const char *method)
2651 {
2652  VALUE v;
2653 
2654  if (FIXNUM_P(val)) return val;
2655  if (RB_TYPE_P(val, T_BIGNUM)) return val;
2656  v = convert_type(val, "Integer", method, TRUE);
2657  if (!rb_obj_is_kind_of(v, rb_cInteger)) {
2658  const char *cname = rb_obj_classname(val);
2659  rb_raise(rb_eTypeError, "can't convert %s to Integer (%s#%s gives %s)",
2660  cname, cname, method, rb_obj_classname(v));
2661  }
2662  return v;
2663 }
2664 
2665 VALUE
2666 rb_check_to_integer(VALUE val, const char *method)
2667 {
2668  VALUE v;
2669 
2670  if (FIXNUM_P(val)) return val;
2671  if (RB_TYPE_P(val, T_BIGNUM)) return val;
2672  v = convert_type(val, "Integer", method, FALSE);
2673  if (!rb_obj_is_kind_of(v, rb_cInteger)) {
2674  return Qnil;
2675  }
2676  return v;
2677 }
2678 
2679 VALUE
2681 {
2682  return rb_to_integer(val, "to_int");
2683 }
2684 
2685 VALUE
2687 {
2688  return rb_check_to_integer(val, "to_int");
2689 }
2690 
2691 static VALUE
2693 {
2694  VALUE tmp;
2695 
2696  switch (TYPE(val)) {
2697  case T_FLOAT:
2698  if (base != 0) goto arg_error;
2699  if (RFLOAT_VALUE(val) <= (double)FIXNUM_MAX
2700  && RFLOAT_VALUE(val) >= (double)FIXNUM_MIN) {
2701  break;
2702  }
2703  return rb_dbl2big(RFLOAT_VALUE(val));
2704 
2705  case T_FIXNUM:
2706  case T_BIGNUM:
2707  if (base != 0) goto arg_error;
2708  return val;
2709 
2710  case T_STRING:
2711  string_conv:
2712  return rb_str_to_inum(val, base, TRUE);
2713 
2714  case T_NIL:
2715  if (base != 0) goto arg_error;
2716  rb_raise(rb_eTypeError, "can't convert nil into Integer");
2717  break;
2718 
2719  default:
2720  break;
2721  }
2722  if (base != 0) {
2723  tmp = rb_check_string_type(val);
2724  if (!NIL_P(tmp)) goto string_conv;
2725  arg_error:
2726  rb_raise(rb_eArgError, "base specified for non string value");
2727  }
2728  tmp = convert_type(val, "Integer", "to_int", FALSE);
2729  if (NIL_P(tmp)) {
2730  return rb_to_integer(val, "to_i");
2731  }
2732  return tmp;
2733 
2734 }
2735 
2736 VALUE
2738 {
2739  return rb_convert_to_integer(val, 0);
2740 }
2741 
2742 /*
2743  * call-seq:
2744  * Integer(arg,base=0) -> integer
2745  *
2746  * Converts <i>arg</i> to a <code>Fixnum</code> or <code>Bignum</code>.
2747  * Numeric types are converted directly (with floating point numbers
2748  * being truncated). <i>base</i> (0, or between 2 and 36) is a base for
2749  * integer string representation. If <i>arg</i> is a <code>String</code>,
2750  * when <i>base</i> is omitted or equals to zero, radix indicators
2751  * (<code>0</code>, <code>0b</code>, and <code>0x</code>) are honored.
2752  * In any case, strings should be strictly conformed to numeric
2753  * representation. This behavior is different from that of
2754  * <code>String#to_i</code>. Non string values will be converted using
2755  * <code>to_int</code>, and <code>to_i</code>.
2756  *
2757  * Integer(123.999) #=> 123
2758  * Integer("0x1a") #=> 26
2759  * Integer(Time.new) #=> 1204973019
2760  * Integer("0930", 10) #=> 930
2761  * Integer("111", 2) #=> 7
2762  */
2763 
2764 static VALUE
2766 {
2767  VALUE arg = Qnil;
2768  int base = 0;
2769 
2770  switch (argc) {
2771  case 2:
2772  base = NUM2INT(argv[1]);
2773  case 1:
2774  arg = argv[0];
2775  break;
2776  default:
2777  /* should cause ArgumentError */
2778  rb_scan_args(argc, argv, "11", NULL, NULL);
2779  }
2780  return rb_convert_to_integer(arg, base);
2781 }
2782 
2783 double
2784 rb_cstr_to_dbl(const char *p, int badcheck)
2785 {
2786  const char *q;
2787  char *end;
2788  double d;
2789  const char *ellipsis = "";
2790  int w;
2791  enum {max_width = 20};
2792 #define OutOfRange() ((end - p > max_width) ? \
2793  (w = max_width, ellipsis = "...") : \
2794  (w = (int)(end - p), ellipsis = ""))
2795 
2796  if (!p) return 0.0;
2797  q = p;
2798  while (ISSPACE(*p)) p++;
2799 
2800  if (!badcheck && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
2801  return 0.0;
2802  }
2803 
2804  d = strtod(p, &end);
2805  if (errno == ERANGE) {
2806  OutOfRange();
2807  rb_warning("Float %.*s%s out of range", w, p, ellipsis);
2808  errno = 0;
2809  }
2810  if (p == end) {
2811  if (badcheck) {
2812  bad:
2813  rb_invalid_str(q, "Float()");
2814  }
2815  return d;
2816  }
2817  if (*end) {
2818  char buf[DBL_DIG * 4 + 10];
2819  char *n = buf;
2820  char *e = buf + sizeof(buf) - 1;
2821  char prev = 0;
2822 
2823  while (p < end && n < e) prev = *n++ = *p++;
2824  while (*p) {
2825  if (*p == '_') {
2826  /* remove underscores between digits */
2827  if (badcheck) {
2828  if (n == buf || !ISDIGIT(prev)) goto bad;
2829  ++p;
2830  if (!ISDIGIT(*p)) goto bad;
2831  }
2832  else {
2833  while (*++p == '_');
2834  continue;
2835  }
2836  }
2837  prev = *p++;
2838  if (n < e) *n++ = prev;
2839  }
2840  *n = '\0';
2841  p = buf;
2842 
2843  if (!badcheck && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
2844  return 0.0;
2845  }
2846 
2847  d = strtod(p, &end);
2848  if (errno == ERANGE) {
2849  OutOfRange();
2850  rb_warning("Float %.*s%s out of range", w, p, ellipsis);
2851  errno = 0;
2852  }
2853  if (badcheck) {
2854  if (!end || p == end) goto bad;
2855  while (*end && ISSPACE(*end)) end++;
2856  if (*end) goto bad;
2857  }
2858  }
2859  if (errno == ERANGE) {
2860  errno = 0;
2861  OutOfRange();
2862  rb_raise(rb_eArgError, "Float %.*s%s out of range", w, q, ellipsis);
2863  }
2864  return d;
2865 }
2866 
2867 double
2868 rb_str_to_dbl(VALUE str, int badcheck)
2869 {
2870  char *s;
2871  long len;
2872  double ret;
2873  VALUE v = 0;
2874 
2875  StringValue(str);
2876  s = RSTRING_PTR(str);
2877  len = RSTRING_LEN(str);
2878  if (s) {
2879  if (badcheck && memchr(s, '\0', len)) {
2880  rb_raise(rb_eArgError, "string for Float contains null byte");
2881  }
2882  if (s[len]) { /* no sentinel somehow */
2883  char *p = ALLOCV(v, len);
2884  MEMCPY(p, s, char, len);
2885  p[len] = '\0';
2886  s = p;
2887  }
2888  }
2889  ret = rb_cstr_to_dbl(s, badcheck);
2890  if (v)
2891  ALLOCV_END(v);
2892  return ret;
2893 }
2894 
2895 VALUE
2897 {
2898  switch (TYPE(val)) {
2899  case T_FIXNUM:
2900  return DBL2NUM((double)FIX2LONG(val));
2901 
2902  case T_FLOAT:
2903  return val;
2904 
2905  case T_BIGNUM:
2906  return DBL2NUM(rb_big2dbl(val));
2907 
2908  case T_STRING:
2909  return DBL2NUM(rb_str_to_dbl(val, TRUE));
2910 
2911  case T_NIL:
2912  rb_raise(rb_eTypeError, "can't convert nil into Float");
2913  break;
2914 
2915  default:
2916  return rb_convert_type(val, T_FLOAT, "Float", "to_f");
2917  }
2918 
2919  UNREACHABLE;
2920 }
2921 
2922 /*
2923  * call-seq:
2924  * Float(arg) -> float
2925  *
2926  * Returns <i>arg</i> converted to a float. Numeric types are converted
2927  * directly, the rest are converted using <i>arg</i>.to_f. As of Ruby
2928  * 1.8, converting <code>nil</code> generates a <code>TypeError</code>.
2929  *
2930  * Float(1) #=> 1.0
2931  * Float("123.456") #=> 123.456
2932  */
2933 
2934 static VALUE
2936 {
2937  return rb_Float(arg);
2938 }
2939 
2940 VALUE
2942 {
2943  if (RB_TYPE_P(val, T_FLOAT)) return val;
2944  if (!rb_obj_is_kind_of(val, rb_cNumeric)) {
2945  rb_raise(rb_eTypeError, "can't convert %s into Float",
2946  NIL_P(val) ? "nil" :
2947  val == Qtrue ? "true" :
2948  val == Qfalse ? "false" :
2949  rb_obj_classname(val));
2950  }
2951  return rb_convert_type(val, T_FLOAT, "Float", "to_f");
2952 }
2953 
2954 VALUE
2956 {
2957  if (RB_TYPE_P(val, T_FLOAT)) return val;
2958  if (!rb_obj_is_kind_of(val, rb_cNumeric)) {
2959  return Qnil;
2960  }
2961  return rb_check_convert_type(val, T_FLOAT, "Float", "to_f");
2962 }
2963 
2964 double
2966 {
2967  switch (TYPE(val)) {
2968  case T_FLOAT:
2969  return RFLOAT_VALUE(val);
2970 
2971  case T_STRING:
2972  rb_raise(rb_eTypeError, "no implicit conversion to float from string");
2973  break;
2974 
2975  case T_NIL:
2976  rb_raise(rb_eTypeError, "no implicit conversion to float from nil");
2977  break;
2978 
2979  default:
2980  break;
2981  }
2982 
2983  return RFLOAT_VALUE(rb_Float(val));
2984 }
2985 
2986 VALUE
2988 {
2989  VALUE tmp = rb_check_string_type(val);
2990  if (NIL_P(tmp))
2991  tmp = rb_convert_type(val, T_STRING, "String", "to_s");
2992  return tmp;
2993 }
2994 
2995 
2996 /*
2997  * call-seq:
2998  * String(arg) -> string
2999  *
3000  * Converts <i>arg</i> to a <code>String</code> by calling its
3001  * <code>to_s</code> method.
3002  *
3003  * String(self) #=> "main"
3004  * String(self.class) #=> "Object"
3005  * String(123456) #=> "123456"
3006  */
3007 
3008 static VALUE
3010 {
3011  return rb_String(arg);
3012 }
3013 
3014 VALUE
3016 {
3017  VALUE tmp = rb_check_array_type(val);
3018 
3019  if (NIL_P(tmp)) {
3020  tmp = rb_check_convert_type(val, T_ARRAY, "Array", "to_a");
3021  if (NIL_P(tmp)) {
3022  return rb_ary_new3(1, val);
3023  }
3024  }
3025  return tmp;
3026 }
3027 
3028 /*
3029  * call-seq:
3030  * Array(arg) -> array
3031  *
3032  * Returns +arg+ as an Array.
3033  *
3034  * First tries to call Array#to_ary on +arg+, then Array#to_a.
3035  *
3036  * Array(1..5) #=> [1, 2, 3, 4, 5]
3037  */
3038 
3039 static VALUE
3041 {
3042  return rb_Array(arg);
3043 }
3044 
3045 VALUE
3047 {
3048  VALUE tmp;
3049 
3050  if (NIL_P(val)) return rb_hash_new();
3051  tmp = rb_check_hash_type(val);
3052  if (NIL_P(tmp)) {
3053  if (RB_TYPE_P(val, T_ARRAY) && RARRAY_LEN(val) == 0)
3054  return rb_hash_new();
3055  rb_raise(rb_eTypeError, "can't convert %s into Hash", rb_obj_classname(val));
3056  }
3057  return tmp;
3058 }
3059 
3060 /*
3061  * call-seq:
3062  * Hash(arg) -> hash
3063  *
3064  * Converts <i>arg</i> to a <code>Hash</code> by calling
3065  * <i>arg</i><code>.to_hash</code>. Returns an empty <code>Hash</code> when
3066  * <i>arg</i> is <tt>nil</tt> or <tt>[]</tt>.
3067  *
3068  * Hash([]) #=> {}
3069  * Hash(nil) #=> {}
3070  * Hash(key: :value) #=> {:key => :value}
3071  * Hash([1, 2, 3]) #=> TypeError
3072  */
3073 
3074 static VALUE
3076 {
3077  return rb_Hash(arg);
3078 }
3079 
3080 /*
3081  * Document-class: Class
3082  *
3083  * Classes in Ruby are first-class objects---each is an instance of
3084  * class <code>Class</code>.
3085  *
3086  * Typically, you create a new class by using:
3087  *
3088  * class Name
3089  * # some class describing the class behavior
3090  * end
3091  *
3092  * When a new class is created, an object of type Class is initialized and
3093  * assigned to a global constant (<code>Name</code> in this case).
3094  *
3095  * When <code>Name.new</code> is called to create a new object, the
3096  * <code>new</code> method in <code>Class</code> is run by default.
3097  * This can be demonstrated by overriding <code>new</code> in
3098  * <code>Class</code>:
3099  *
3100  * class Class
3101  * alias oldNew new
3102  * def new(*args)
3103  * print "Creating a new ", self.name, "\n"
3104  * oldNew(*args)
3105  * end
3106  * end
3107  *
3108  *
3109  * class Name
3110  * end
3111  *
3112  *
3113  * n = Name.new
3114  *
3115  * <em>produces:</em>
3116  *
3117  * Creating a new Name
3118  *
3119  * Classes, modules, and objects are interrelated. In the diagram
3120  * that follows, the vertical arrows represent inheritance, and the
3121  * parentheses meta-classes. All metaclasses are instances
3122  * of the class `Class'.
3123  * +---------+ +-...
3124  * | | |
3125  * BasicObject-----|-->(BasicObject)-------|-...
3126  * ^ | ^ |
3127  * | | | |
3128  * Object---------|----->(Object)---------|-...
3129  * ^ | ^ |
3130  * | | | |
3131  * +-------+ | +--------+ |
3132  * | | | | | |
3133  * | Module-|---------|--->(Module)-|-...
3134  * | ^ | | ^ |
3135  * | | | | | |
3136  * | Class-|---------|---->(Class)-|-...
3137  * | ^ | | ^ |
3138  * | +---+ | +----+
3139  * | |
3140  * obj--->OtherClass---------->(OtherClass)-----------...
3141  *
3142  */
3143 
3144 
3163 /* Document-class: BasicObject
3164  *
3165  * BasicObject is the parent class of all classes in Ruby. It's an explicit
3166  * blank class.
3167  *
3168  * BasicObject can be used for creating object hierarchies independent of
3169  * Ruby's object hierarchy, proxy objects like the Delegator class, or other
3170  * uses where namespace pollution from Ruby's methods and classes must be
3171  * avoided.
3172  *
3173  * To avoid polluting BasicObject for other users an appropriately named
3174  * subclass of BasicObject should be created instead of directly modifying
3175  * BasicObject:
3176  *
3177  * class MyObjectSystem < BasicObject
3178  * end
3179  *
3180  * BasicObject does not include Kernel (for methods like +puts+) and
3181  * BasicObject is outside of the namespace of the standard library so common
3182  * classes will not be found without a using a full class path.
3183  *
3184  * A variety of strategies can be used to provide useful portions of the
3185  * standard library to subclasses of BasicObject. A subclass could
3186  * <code>include Kernel</code> to obtain +puts+, +exit+, etc. A custom
3187  * Kernel-like module could be created and included or delegation can be used
3188  * via #method_missing:
3189  *
3190  * class MyObjectSystem < BasicObject
3191  * DELEGATE = [:puts, :p]
3192  *
3193  * def method_missing(name, *args, &block)
3194  * super unless DELEGATE.include? name
3195  * ::Kernel.send(name, *args, &block)
3196  * end
3197  *
3198  * def respond_to_missing?(name, include_private = false)
3199  * DELEGATE.include?(name) or super
3200  * end
3201  * end
3202  *
3203  * Access to classes and modules from the Ruby standard library can be
3204  * obtained in a BasicObject subclass by referencing the desired constant
3205  * from the root like <code>::File</code> or <code>::Enumerator</code>.
3206  * Like #method_missing, #const_missing can be used to delegate constant
3207  * lookup to +Object+:
3208  *
3209  * class MyObjectSystem < BasicObject
3210  * def self.const_missing(name)
3211  * ::Object.const_get(name)
3212  * end
3213  * end
3214  */
3215 
3216 /* Document-class: Object
3217  *
3218  * Object is the default root of all Ruby objects. Object inherits from
3219  * BasicObject which allows creating alternate object hierarchies. Methods
3220  * on object are available to all classes unless explicitly overridden.
3221  *
3222  * Object mixes in the Kernel module, making the built-in kernel functions
3223  * globally accessible. Although the instance methods of Object are defined
3224  * by the Kernel module, we have chosen to document them here for clarity.
3225  *
3226  * When referencing constants in classes inheriting from Object you do not
3227  * need to use the full namespace. For example, referencing +File+ inside
3228  * +YourClass+ will find the top-level File class.
3229  *
3230  * In the descriptions of Object's methods, the parameter <i>symbol</i> refers
3231  * to a symbol, which is either a quoted string or a Symbol (such as
3232  * <code>:name</code>).
3233  */
3234 
3235 void
3237 {
3238  int i;
3239 
3241 
3242 #if 0
3243  // teach RDoc about these classes
3244  rb_cBasicObject = rb_define_class("BasicObject", Qnil);
3246  rb_cModule = rb_define_class("Module", rb_cObject);
3247  rb_cClass = rb_define_class("Class", rb_cModule);
3248 #endif
3249 
3250 #undef rb_intern
3251 #define rb_intern(str) rb_intern_const(str)
3252 
3259 
3260  rb_define_private_method(rb_cBasicObject, "singleton_method_added", rb_obj_dummy, 1);
3261  rb_define_private_method(rb_cBasicObject, "singleton_method_removed", rb_obj_dummy, 1);
3262  rb_define_private_method(rb_cBasicObject, "singleton_method_undefined", rb_obj_dummy, 1);
3263 
3264  /* Document-module: Kernel
3265  *
3266  * The Kernel module is included by class Object, so its methods are
3267  * available in every Ruby object.
3268  *
3269  * The Kernel instance methods are documented in class Object while the
3270  * module methods are documented here. These methods are called without a
3271  * receiver and thus can be called in functional form:
3272  *
3273  * sprintf "%.1f", 1.234 #=> "1.2"
3274  *
3275  */
3276  rb_mKernel = rb_define_module("Kernel");
3282  rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1);
3283  rb_define_private_method(rb_cModule, "method_removed", rb_obj_dummy, 1);
3284  rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy, 1);
3285 
3286  rb_define_method(rb_mKernel, "nil?", rb_false, 0);
3287  rb_define_method(rb_mKernel, "===", rb_equal, 1);
3293 
3295  rb_define_method(rb_mKernel, "singleton_class", rb_obj_singleton_class, 0);
3298  rb_define_method(rb_mKernel, "initialize_copy", rb_obj_init_copy, 1);
3299  rb_define_method(rb_mKernel, "initialize_dup", rb_obj_init_dup_clone, 1);
3300  rb_define_method(rb_mKernel, "initialize_clone", rb_obj_init_dup_clone, 1);
3301 
3303  rb_define_method(rb_mKernel, "tainted?", rb_obj_tainted, 0);
3304  rb_define_method(rb_mKernel, "untaint", rb_obj_untaint, 0);
3305  rb_define_method(rb_mKernel, "untrust", rb_obj_untrust, 0);
3306  rb_define_method(rb_mKernel, "untrusted?", rb_obj_untrusted, 0);
3308  rb_define_method(rb_mKernel, "freeze", rb_obj_freeze, 0);
3310 
3312  rb_define_method(rb_mKernel, "inspect", rb_obj_inspect, 0);
3313  rb_define_method(rb_mKernel, "methods", rb_obj_methods, -1); /* in class.c */
3314  rb_define_method(rb_mKernel, "singleton_methods", rb_obj_singleton_methods, -1); /* in class.c */
3315  rb_define_method(rb_mKernel, "protected_methods", rb_obj_protected_methods, -1); /* in class.c */
3316  rb_define_method(rb_mKernel, "private_methods", rb_obj_private_methods, -1); /* in class.c */
3317  rb_define_method(rb_mKernel, "public_methods", rb_obj_public_methods, -1); /* in class.c */
3318  rb_define_method(rb_mKernel, "instance_variables", rb_obj_instance_variables, 0); /* in variable.c */
3319  rb_define_method(rb_mKernel, "instance_variable_get", rb_obj_ivar_get, 1);
3320  rb_define_method(rb_mKernel, "instance_variable_set", rb_obj_ivar_set, 2);
3321  rb_define_method(rb_mKernel, "instance_variable_defined?", rb_obj_ivar_defined, 1);
3322  rb_define_method(rb_mKernel, "remove_instance_variable",
3323  rb_obj_remove_instance_variable, 1); /* in variable.c */
3324 
3325  rb_define_method(rb_mKernel, "instance_of?", rb_obj_is_instance_of, 1);
3329 
3330  rb_define_global_function("sprintf", rb_f_sprintf, -1); /* in sprintf.c */
3331  rb_define_global_function("format", rb_f_sprintf, -1); /* in sprintf.c */
3332 
3333  rb_define_global_function("Integer", rb_f_integer, -1);
3335 
3336  rb_define_global_function("String", rb_f_string, 1);
3339 
3340  rb_cNilClass = rb_define_class("NilClass", rb_cObject);
3341  rb_define_method(rb_cNilClass, "to_i", nil_to_i, 0);
3342  rb_define_method(rb_cNilClass, "to_f", nil_to_f, 0);
3343  rb_define_method(rb_cNilClass, "to_s", nil_to_s, 0);
3344  rb_define_method(rb_cNilClass, "to_a", nil_to_a, 0);
3345  rb_define_method(rb_cNilClass, "to_h", nil_to_h, 0);
3346  rb_define_method(rb_cNilClass, "inspect", nil_inspect, 0);
3350 
3351  rb_define_method(rb_cNilClass, "nil?", rb_true, 0);
3354  /*
3355  * An alias of +nil+
3356  */
3357  rb_define_global_const("NIL", Qnil);
3358 
3359  rb_define_method(rb_cModule, "freeze", rb_mod_freeze, 0);
3367  rb_define_method(rb_cModule, "initialize_copy", rb_mod_init_copy, 1); /* in class.c */
3369  rb_define_alias(rb_cModule, "inspect", "to_s");
3370  rb_define_method(rb_cModule, "included_modules", rb_mod_included_modules, 0); /* in class.c */
3371  rb_define_method(rb_cModule, "include?", rb_mod_include_p, 1); /* in class.c */
3372  rb_define_method(rb_cModule, "name", rb_mod_name, 0); /* in variable.c */
3373  rb_define_method(rb_cModule, "ancestors", rb_mod_ancestors, 0); /* in class.c */
3374 
3379 
3381  rb_define_method(rb_cModule, "initialize", rb_mod_initialize, 0);
3382  rb_define_method(rb_cModule, "instance_methods", rb_class_instance_methods, -1); /* in class.c */
3383  rb_define_method(rb_cModule, "public_instance_methods",
3384  rb_class_public_instance_methods, -1); /* in class.c */
3385  rb_define_method(rb_cModule, "protected_instance_methods",
3386  rb_class_protected_instance_methods, -1); /* in class.c */
3387  rb_define_method(rb_cModule, "private_instance_methods",
3388  rb_class_private_instance_methods, -1); /* in class.c */
3389 
3390  rb_define_method(rb_cModule, "constants", rb_mod_constants, -1); /* in variable.c */
3391  rb_define_method(rb_cModule, "const_get", rb_mod_const_get, -1);
3392  rb_define_method(rb_cModule, "const_set", rb_mod_const_set, 2);
3393  rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, -1);
3394  rb_define_private_method(rb_cModule, "remove_const",
3395  rb_mod_remove_const, 1); /* in variable.c */
3396  rb_define_method(rb_cModule, "const_missing",
3397  rb_mod_const_missing, 1); /* in variable.c */
3398  rb_define_method(rb_cModule, "class_variables",
3399  rb_mod_class_variables, -1); /* in variable.c */
3400  rb_define_method(rb_cModule, "remove_class_variable",
3401  rb_mod_remove_cvar, 1); /* in variable.c */
3402  rb_define_method(rb_cModule, "class_variable_get", rb_mod_cvar_get, 1);
3403  rb_define_method(rb_cModule, "class_variable_set", rb_mod_cvar_set, 2);
3404  rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
3405  rb_define_method(rb_cModule, "public_constant", rb_mod_public_constant, -1); /* in variable.c */
3406  rb_define_method(rb_cModule, "private_constant", rb_mod_private_constant, -1); /* in variable.c */
3407  rb_define_method(rb_cModule, "singleton_class?", rb_mod_singleton_p, 0);
3408 
3409  rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
3411  rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1);
3412  rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);
3414  rb_undef_method(rb_cClass, "extend_object");
3415  rb_undef_method(rb_cClass, "append_features");
3416  rb_undef_method(rb_cClass, "prepend_features");
3417 
3418  /*
3419  * Document-class: Data
3420  *
3421  * This is a recommended base class for C extensions using Data_Make_Struct
3422  * or Data_Wrap_Struct, see README.EXT for details.
3423  */
3424  rb_cData = rb_define_class("Data", rb_cObject);
3426 
3427  rb_cTrueClass = rb_define_class("TrueClass", rb_cObject);
3429  rb_define_alias(rb_cTrueClass, "inspect", "to_s");
3435  /*
3436  * An alias of +true+
3437  */
3438  rb_define_global_const("TRUE", Qtrue);
3439 
3440  rb_cFalseClass = rb_define_class("FalseClass", rb_cObject);
3442  rb_define_alias(rb_cFalseClass, "inspect", "to_s");
3448  /*
3449  * An alias of +false+
3450  */
3451  rb_define_global_const("FALSE", Qfalse);
3452 
3453  for (i=0; conv_method_names[i].method; i++) {
3455  }
3456 }
void rb_define_global_const(const char *, VALUE)
Definition: variable.c:2236
VALUE(* rb_alloc_func_t)(VALUE)
Definition: intern.h:374
#define RBASIC_CLEAR_CLASS(obj)
Definition: internal.h:607
VALUE rb_check_to_float(VALUE val)
Definition: object.c:2955
VALUE rb_cvar_get(VALUE, ID)
Definition: variable.c:2381
#define T_OBJECT
Definition: ruby.h:477
#define ISDIGIT(c)
Definition: ruby.h:1775
static VALUE rb_obj_ivar_defined(VALUE obj, VALUE iv)
Definition: object.c:2423
static VALUE nil_to_h(VALUE obj)
Definition: object.c:1193
static VALUE rb_mod_attr_accessor(int argc, VALUE *argv, VALUE klass)
Definition: object.c:2039
static VALUE rb_mod_cmp(VALUE mod, VALUE arg)
Definition: object.c:1656
#define FL_EXIVAR
Definition: ruby.h:1139
VALUE rb_mod_include_p(VALUE mod, VALUE mod2)
Definition: class.c:1026
#define RARRAY_LEN(a)
Definition: ruby.h:878
#define FALSE
Definition: nkf.h:174
void rb_check_inheritable(VALUE super)
Ensures a class can be derived from super.
Definition: class.c:206
VALUE rb_mod_name(VALUE)
Definition: variable.c:206
int rb_is_class_name(VALUE name)
Definition: ripper.c:17392
VALUE rb_obj_id(VALUE obj)
Definition: gc.c:2373
#define RCLASS_CONST_TBL(c)
Definition: internal.h:293
#define T_FIXNUM
Definition: ruby.h:489
Definition: st.h:69
VALUE rb_obj_private_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1337
VALUE rb_inspect(VALUE obj)
Definition: object.c:471
VALUE rb_Hash(VALUE val)
Definition: object.c:3046
static VALUE rb_convert_to_integer(VALUE val, int base)
Definition: object.c:2692
#define NUM2INT(x)
Definition: ruby.h:630
#define id_match
Definition: object.c:41
void rb_undef_alloc_func(VALUE)
Definition: vm_method.c:518
double rb_cstr_to_dbl(const char *p, int badcheck)
Definition: object.c:2784
double rb_str_to_dbl(VALUE str, int badcheck)
Definition: object.c:2868
VALUE rb_f_sprintf(int, const VALUE *)
Definition: sprintf.c:415
#define DBL_DIG
Definition: numeric.c:67
void rb_obj_copy_ivar(VALUE dest, VALUE obj)
Definition: object.c:256
#define QUOTE_ID(id)
Definition: internal.h:715
#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
#define FIXNUM_MAX
Definition: ruby.h:228
#define Qtrue
Definition: ruby.h:426
int st_insert(st_table *, st_data_t, st_data_t)
static VALUE rb_mod_ge(VALUE mod, VALUE arg)
Definition: object.c:1616
static VALUE rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val)
Definition: object.c:2502
VALUE rb_equal(VALUE obj1, VALUE obj2)
Definition: object.c:89
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
static VALUE rb_mod_lt(VALUE mod, VALUE arg)
Definition: object.c:1596
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1500
#define FIXNUM_MIN
Definition: ruby.h:229
VALUE rb_eTypeError
Definition: error.c:548
VALUE rb_obj_tap(VALUE obj)
Definition: object.c:696
#define UNREACHABLE
Definition: ruby.h:42
static VALUE rb_mod_attr_reader(int argc, VALUE *argv, VALUE klass)
Definition: object.c:1979
VALUE rb_obj_taint(VALUE obj)
Definition: object.c:974
void rb_cvar_set(VALUE, ID, VALUE)
Definition: variable.c:2348
void st_free_table(st_table *)
Definition: st.c:334
VALUE rb_str_concat(VALUE, VALUE)
Definition: string.c:2340
static void init_copy(VALUE dest, VALUE obj)
Definition: object.c:283
VALUE rb_convert_type(VALUE val, int type, const char *tname, const char *method)
Definition: object.c:2617
static VALUE false_and(VALUE obj, VALUE obj2)
Definition: object.c:1322
#define SYM2ID(x)
Definition: ruby.h:356
#define RUBY_DTRACE_OBJECT_CREATE_ENABLED()
Definition: probes.h:39
VALUE rb_mod_init_copy(VALUE clone, VALUE orig)
Definition: class.c:319
#define rb_check_trusted(obj)
Definition: intern.h:283
static VALUE nil_inspect(VALUE obj)
Definition: object.c:1206
VALUE rb_obj_trust(VALUE obj)
Definition: object.c:1041
static VALUE rb_mod_attr_writer(int argc, VALUE *argv, VALUE klass)
Definition: object.c:2011
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:775
static VALUE rb_obj_ivar_get(VALUE obj, VALUE iv)
Definition: object.c:2352
void Init_class_hierarchy(void)
Definition: class.c:535
ID rb_check_attr_id(ID id)
Definition: object.c:1957
#define RBASIC_SET_CLASS(obj, cls)
Definition: internal.h:609
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1854
double rb_num2dbl(VALUE val)
Definition: object.c:2965
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1115
static struct conv_method_tbl conv_method_names[]
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
Definition: thread.c:4982
static VALUE rb_obj_cmp(VALUE obj1, VALUE obj2)
Definition: object.c:1441
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
int rb_const_defined(VALUE, ID)
Definition: variable.c:2124
VALUE rb_cClass
Definition: object.c:32
#define RCLASS_M_TBL_WRAPPER(c)
Definition: internal.h:294
VALUE rb_cModule
Definition: object.c:31
void rb_include_module(VALUE klass, VALUE module)
Definition: class.c:827
VALUE rb_to_float(VALUE val)
Definition: object.c:2941
static VALUE rb_mod_singleton_p(VALUE klass)
Definition: object.c:2560
static VALUE rb_obj_match(VALUE obj1, VALUE obj2)
Definition: object.c:1401
static VALUE rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
Definition: object.c:2090
static const char invalid_attribute_name[]
Definition: object.c:1948
VALUE rb_Integer(VALUE val)
Definition: object.c:2737
#define T_ARRAY
Definition: ruby.h:484
st_data_t st_index_t
Definition: st.h:48
double rb_big2dbl(VALUE x)
Definition: bignum.c:5267
static VALUE class_search_ancestor(VALUE cl, VALUE c)
Definition: object.c:662
#define RGENGC_WB_PROTECTED_OBJECT
Definition: ruby.h:723
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1684
static int rb_is_attr_name(VALUE name)
Definition: object.c:1943
VALUE rb_to_int(VALUE val)
Definition: object.c:2680
#define id_eq
Definition: object.c:39
ID rb_check_id(volatile VALUE *namep)
Returns ID for the given name if it is interned already, or 0.
Definition: ripper.c:17321
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
Definition: ripper.c:17363
#define FIXNUM_P(f)
Definition: ruby.h:347
VALUE rb_obj_untaint(VALUE obj)
Definition: object.c:994
static VALUE nil_to_i(VALUE obj)
Definition: object.c:1131
void rb_undef_method(VALUE klass, const char *name)
Definition: class.c:1506
VALUE rb_mod_module_exec(int, VALUE *, VALUE)
Definition: vm_eval.c:1704
VALUE rb_ivar_defined(VALUE, ID)
Definition: variable.c:1207
static VALUE rb_obj_not_match(VALUE obj1, VALUE obj2)
Definition: object.c:1415
static VALUE rb_obj_dummy(void)
Definition: object.c:931
VALUE rb_mod_remove_cvar(VALUE, VALUE)
Definition: variable.c:2569
#define OBJ_TAINTED(x)
Definition: ruby.h:1176
void rb_ivar_foreach(VALUE, int(*)(ANYARGS), st_data_t)
Definition: variable.c:1274
const char * rb_obj_classname(VALUE)
Definition: variable.c:406
#define rb_ary_new2
Definition: intern.h:90
void rb_name_error_str(VALUE str, const char *fmt,...)
Definition: error.c:982
#define OutOfRange()
#define id_for_setter(name, type, message)
Definition: object.c:1909
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
static VALUE rb_f_array(VALUE obj, VALUE arg)
Definition: object.c:3040
#define NEWOBJ_OF(obj, type, klass, flags)
Definition: ruby.h:694
static VALUE rb_mod_cvar_get(VALUE obj, VALUE iv)
Definition: object.c:2460
#define FL_SINGLETON
Definition: ruby.h:1133
#define strtod(s, e)
Definition: util.h:74
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1628
int rb_is_const_id(ID id)
Definition: ripper.c:17268
VALUE rb_obj_class(VALUE obj)
Definition: object.c:227
int rb_is_instance_id(ID id)
Definition: ripper.c:17286
VALUE rb_obj_dup(VALUE obj)
Definition: object.c:407
#define RB_TYPE_P(obj, type)
Definition: ruby.h:1664
VALUE rb_eNameError
Definition: error.c:553
int st_lookup(st_table *, st_data_t, st_data_t *)
static VALUE true_or(VALUE obj, VALUE obj2)
Definition: object.c:1266
VALUE rb_obj_not(VALUE obj)
Definition: object.c:184
rb_encoding * rb_default_external_encoding(void)
Definition: encoding.c:1351
#define FL_TEST(x, f)
Definition: ruby.h:1169
static VALUE false_or(VALUE obj, VALUE obj2)
Definition: object.c:1338
VALUE rb_cvar_defined(VALUE, ID)
Definition: variable.c:2408
#define id_init_dup
Definition: object.c:45
VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
Definition: class.c:604
static VALUE rb_to_integer(VALUE val, const char *method)
Definition: object.c:2650
#define ROBJECT_IVPTR(o)
Definition: ruby.h:778
#define rb_intern_str(string)
Definition: generator.h:17
VALUE rb_class_name(VALUE)
Definition: variable.c:391
VALUE rb_obj_reveal(VALUE obj, VALUE klass)
Definition: object.c:62
VALUE rb_dbl2big(double d)
Definition: bignum.c:5211
VALUE rb_class_new_instance(int argc, VALUE *argv, VALUE klass)
Definition: object.c:1856
#define ALLOC_N(type, n)
Definition: ruby.h:1333
int rb_block_given_p(void)
Definition: eval.c:712
static VALUE rb_class_allocate_instance(VALUE klass)
Definition: object.c:1837
static VALUE rb_f_hash(VALUE obj, VALUE arg)
Definition: object.c:3075
void rb_gc_copy_finalizer(VALUE dest, VALUE obj)
Definition: gc.c:1998
static VALUE nil_to_f(VALUE obj)
Definition: object.c:1146
#define val
static VALUE rb_true(VALUE obj)
Definition: object.c:1370
VALUE rb_str_to_inum(VALUE str, int base, int badcheck)
Definition: bignum.c:4127
void rb_attr(VALUE, ID, int, int, int)
Definition: vm_method.c:859
#define T_NIL
Definition: ruby.h:476
#define id_const_missing
Definition: object.c:46
VALUE rb_str_cat2(VALUE, const char *)
Definition: string.c:2159
VALUE rb_obj_as_string(VALUE)
Definition: string.c:1011
VALUE rb_mod_attr(int argc, VALUE *argv, VALUE klass)
Definition: object.c:1990
static VALUE rb_mod_freeze(VALUE mod)
Definition: object.c:1530
VALUE rb_check_to_integer(VALUE val, const char *method)
Definition: object.c:2666
long rb_objid_hash(st_index_t index)
Definition: hash.c:150
VALUE rb_mod_private_constant(int argc, VALUE *argv, VALUE obj)
Definition: variable.c:2288
#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
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:630
VALUE rb_class_get_superclass(VALUE klass)
Definition: object.c:1904
static VALUE rb_obj_singleton_class(VALUE obj)
Definition: object.c:250
#define RCLASS_IV_TBL(c)
Definition: internal.h:292
VALUE rb_obj_freeze(VALUE obj)
Definition: object.c:1077
static VALUE rb_class_initialize(int argc, VALUE *argv, VALUE klass)
Definition: object.c:1754
static int rb_is_attr_id(ID id)
Definition: object.c:1937
#define OBJ_FROZEN(x)
Definition: ruby.h:1185
VALUE rb_class_search_ancestor(VALUE cl, VALUE c)
Definition: object.c:673
#define T_FLOAT
Definition: ruby.h:481
#define TYPE(x)
Definition: ruby.h:505
int argc
Definition: ruby.c:131
#define Qfalse
Definition: ruby.h:425
#define rb_sourcefile()
Definition: tcltklib.c:98
VALUE rb_Float(VALUE val)
Definition: object.c:2896
VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type)
Definition: object.c:71
static VALUE false_xor(VALUE obj, VALUE obj2)
Definition: object.c:1357
#define T_BIGNUM
Definition: ruby.h:487
#define ISUPPER(c)
Definition: ruby.h:1771
#define MEMCPY(p1, p2, type, n)
Definition: ruby.h:1352
rb_alloc_func_t rb_get_alloc_func(VALUE)
Definition: vm_method.c:524
VALUE rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1322
VALUE rb_eEncCompatError
Definition: error.c:555
#define OBJ_FREEZE(x)
Definition: ruby.h:1186
VALUE rb_mod_constants(int, VALUE *, VALUE)
Definition: variable.c:2068
#define ALLOCV_END(v)
Definition: ruby.h:1349
VALUE rb_obj_equal(VALUE obj1, VALUE obj2)
Definition: object.c:142
VALUE rb_cFalseClass
Definition: object.c:37
static VALUE rb_f_float(VALUE obj, VALUE arg)
Definition: object.c:2935
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:1880
VALUE rb_str_subseq(VALUE, long, long)
Definition: string.c:1839
#define FL_FINALIZE
Definition: ruby.h:1136
#define rb_intern(str)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
Definition: class.c:1697
static VALUE rb_mod_eqq(VALUE mod, VALUE arg)
Definition: object.c:1547
static VALUE rb_mod_initialize(VALUE module)
Definition: object.c:1715
#define RSTRING_LEN(str)
Definition: ruby.h:841
VALUE rb_yield(VALUE)
Definition: vm_eval.c:942
static ID check_setter_id(VALUE name, int(*valid_id_p)(ID), int(*valid_name_p)(VALUE), const char *message)
Definition: object.c:1912
int errno
#define TRUE
Definition: nkf.h:175
VALUE rb_obj_untrusted(VALUE obj)
Definition: object.c:1012
#define T_DATA
Definition: ruby.h:492
VALUE rb_mod_class_variables(int, VALUE *, VALUE)
Definition: variable.c:2528
VALUE rb_obj_hash(VALUE obj)
Definition: object.c:162
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1250
static VALUE true_to_s(VALUE obj)
Definition: object.c:1229
VALUE rb_hash_new(void)
Definition: hash.c:298
VALUE rb_class_superclass(VALUE klass)
Definition: object.c:1886
int rb_is_local_id(ID id)
Definition: ripper.c:17298
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1728
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1133
VALUE rb_check_hash_type(VALUE hash)
Definition: hash.c:588
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4308
#define PRIsVALUE
Definition: ruby.h:137
unsigned long ID
Definition: ruby.h:89
#define id_init_copy
Definition: object.c:43
#define Qnil
Definition: ruby.h:427
void rb_const_set(VALUE, ID, VALUE)
Definition: variable.c:2160
VALUE rb_mod_public_constant(int argc, VALUE *argv, VALUE obj)
Definition: variable.c:2302
int type
Definition: tcltklib.c:112
VALUE rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1352
#define BUILTIN_TYPE(x)
Definition: ruby.h:502
#define OBJ_TAINT(x)
Definition: ruby.h:1177
unsigned long VALUE
Definition: ruby.h:88
static VALUE nil_to_s(VALUE obj)
Definition: object.c:1159
static VALUE result
Definition: nkf.c:40
#define RBASIC(obj)
Definition: ruby.h:1116
const char * rb_class2name(VALUE)
Definition: variable.c:397
RUBY_EXTERN VALUE rb_cInteger
Definition: ruby.h:1568
#define bad(x)
Definition: _sdbm.c:125
VALUE rb_make_metaclass(VALUE obj, VALUE unused)
Definition: class.c:561
#define rb_ary_new3
Definition: intern.h:91
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
Definition: vm_eval.c:409
VALUE rb_check_convert_type(VALUE val, int type, const char *tname, const char *method)
Definition: object.c:2632
#define rb_enc_asciicompat(enc)
Definition: encoding.h:188
VALUE rb_obj_untrust(VALUE obj)
Definition: object.c:1026
VALUE rb_String(VALUE val)
Definition: object.c:2987
#define IMPLICIT_CONVERSIONS
Definition: object.c:2582
RUBY_EXTERN VALUE rb_cNumeric
Definition: ruby.h:1575
st_table * st_init_numtable(void)
Definition: st.c:272
VALUE rb_obj_remove_instance_variable(VALUE, VALUE)
Definition: variable.c:1403
VALUE rb_str_dup(VALUE)
Definition: string.c:1062
VALUE rb_check_to_int(VALUE val)
Definition: object.c:2686
void Init_Object(void)
Initializes the world of objects and classes.
Definition: object.c:3236
VALUE rb_class_instance_methods(int argc, VALUE *argv, VALUE mod)
Definition: class.c:1205
VALUE rb_cTrueClass
Definition: object.c:36
VALUE rb_class_real(VALUE cl)
Definition: object.c:204
#define FL_UNSET(x, f)
Definition: ruby.h:1173
VALUE rb_cNilClass
Definition: object.c:35
#define ROBJECT(obj)
Definition: ruby.h:1117
void rb_free_const_table(st_table *tbl)
Definition: gc.c:1466
static VALUE rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val)
Definition: object.c:2396
static VALUE true_xor(VALUE obj, VALUE obj2)
Definition: object.c:1282
#define recur(fmt)
#define RSTRING_PTR(str)
Definition: ruby.h:845
int rb_is_const_name(VALUE name)
Definition: ripper.c:17386
int rb_is_local_name(VALUE name)
Definition: ripper.c:17416
VALUE rb_obj_alloc(VALUE klass)
Definition: object.c:1802
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
rb_encoding * rb_enc_get(VALUE obj)
Definition: encoding.c:832
const char * method
Definition: object.c:2568
#define RFLOAT_VALUE(v)
Definition: ruby.h:814
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 INT2FIX(i)
Definition: ruby.h:231
#define RCLASS_SUPER(c)
Definition: classext.h:16
int rb_sourceline(void)
Definition: vm.c:966
VALUE rb_module_new(void)
Definition: class.c:727
static VALUE convert_type(VALUE val, const char *tname, const char *method, int raise)
Definition: object.c:2585
VALUE rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1391
#define ROBJECT_EMBED_LEN_MAX
Definition: ruby.h:761
static VALUE true_and(VALUE obj, VALUE obj2)
Definition: object.c:1244
VALUE rb_check_array_type(VALUE ary)
Definition: array.c:628
static VALUE rb_f_string(VALUE obj, VALUE arg)
Definition: object.c:3009
static VALUE rb_obj_inspect(VALUE obj)
Definition: object.c:565
static VALUE nil_to_a(VALUE obj)
Definition: object.c:1176
#define FL_WB_PROTECTED
Definition: ruby.h:1134
VALUE rb_check_string_type(VALUE)
Definition: string.c:1679
static int rb_special_const_p(VALUE obj)
Definition: ruby.h:1687
#define LONG2FIX(i)
Definition: ruby.h:232
VALUE rb_obj_init_dup_clone(VALUE obj, VALUE orig)
Definition: object.c:436
#define ALLOCV(v, n)
Definition: ruby.h:1346
#define RTEST(v)
Definition: ruby.h:437
#define T_STRING
Definition: ruby.h:482
VALUE rb_mod_remove_const(VALUE, VALUE)
Definition: variable.c:1920
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
#define id_inspect
Definition: object.c:42
VALUE rb_obj_methods(int argc, VALUE *argv, VALUE obj)
Definition: class.c:1294
int rb_method_basic_definition_p(VALUE, ID)
Definition: vm_method.c:1572
VALUE rb_mod_const_missing(VALUE, VALUE)
Definition: variable.c:1519
static VALUE inspect_obj(VALUE obj, VALUE str, int recur)
Definition: object.c:515
VALUE rb_obj_is_kind_of(VALUE obj, VALUE c)
Definition: object.c:653
void rb_obj_infect(VALUE obj1, VALUE obj2)
Definition: object.c:1048
#define id_eql
Definition: object.c:40
VALUE rb_obj_init_copy(VALUE obj, VALUE orig)
Definition: object.c:423
VALUE rb_Array(VALUE val)
Definition: object.c:3015
static VALUE rb_mod_cvar_defined(VALUE obj, VALUE iv)
Definition: object.c:2526
static VALUE rb_class_s_alloc(VALUE klass)
Definition: object.c:1683
static VALUE rb_mod_to_s(VALUE klass)
Definition: object.c:1486
int rb_is_class_id(ID id)
Definition: ripper.c:17274
#define T_CLASS
Definition: ruby.h:478
static VALUE rb_mod_const_set(VALUE mod, VALUE name, VALUE value)
Definition: object.c:2202
#define rb_safe_level()
Definition: tcltklib.c:95
VALUE rb_const_get_at(VALUE, ID)
Definition: variable.c:1886
#define ROBJECT_EMBED
Definition: ruby.h:773
static int inspect_i(st_data_t k, st_data_t v, st_data_t a)
Definition: object.c:486
VALUE rb_obj_tainted(VALUE obj)
Definition: object.c:946
static VALUE rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
Definition: object.c:2232
const char * name
Definition: nkf.c:208
#define FL_SET(x, f)
Definition: ruby.h:1172
int rb_is_instance_name(VALUE name)
Definition: ripper.c:17404
const char * rb_id2name(ID id)
Definition: ripper.c:17227
#define StringValuePtr(v)
Definition: ruby.h:540
VALUE rb_obj_not_equal(VALUE obj1, VALUE obj2)
Definition: object.c:197
VALUE rb_mod_included_modules(VALUE mod)
Definition: class.c:990
#define FL_FREEZE
Definition: ruby.h:1140
Definition: ruby.h:762
static VALUE rb_false(VALUE obj)
Definition: object.c:1385
static VALUE rb_f_integer(int argc, VALUE *argv, VALUE obj)
Definition: object.c:2765
void rb_warning(const char *fmt,...)
Definition: error.c:236
void rb_secure(int)
Definition: safe.c:88
#define QUOTE(str)
Definition: internal.h:714
#define rb_check_frozen(obj)
Definition: intern.h:277
#define CONST_ID(var, str)
Definition: ruby.h:1428
VALUE rb_mKernel
Definition: object.c:29
int rb_eql(VALUE obj1, VALUE obj2)
Definition: object.c:100
static VALUE false_to_s(VALUE obj)
Definition: object.c:1306
void rb_copy_generic_ivar(VALUE, VALUE)
Definition: variable.c:1049
#define SPECIAL_CONST_P(x)
Definition: ruby.h:1165
static ID id_for_attr(VALUE name)
Definition: object.c:1951
void void xfree(void *)
VALUE rb_define_module(const char *name)
Definition: class.c:746
int rb_enc_str_asciionly_p(VALUE)
Definition: string.c:448
VALUE rb_usascii_str_new(const char *, long)
Definition: string.c:540
static VALUE rb_mod_gt(VALUE mod, VALUE arg)
Definition: object.c:1637
#define id_init_clone
Definition: object.c:44
#define SYMBOL_P(x)
Definition: ruby.h:354
#define RCLASS(obj)
Definition: ruby.h:1118
#define mod(x, y)
Definition: date_strftime.c:28
static st_table * immediate_frozen_tbl
Definition: object.c:1053
VALUE rb_obj_clone(VALUE obj)
Definition: object.c:338
static VALUE class_or_module_required(VALUE c)
Definition: object.c:580
#define NULL
Definition: _sdbm.c:103
#define FIX2LONG(x)
Definition: ruby.h:345
#define Qundef
Definition: ruby.h:428
#define T_ICLASS
Definition: ruby.h:479
VALUE rb_obj_hide(VALUE obj)
Definition: object.c:53
void rb_obj_call_init(VALUE obj, int argc, VALUE *argv)
Definition: eval.c:1298
VALUE rb_class_inherited_p(VALUE mod, VALUE arg)
Definition: object.c:1565
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1488
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:2298
VALUE rb_cObject
Definition: object.c:30
void rb_invalid_str(const char *str, const char *type)
Definition: error.c:1190
ID rb_to_id(VALUE)
Definition: string.c:8730
VALUE rb_class_boot(VALUE super)
A utility function that wraps class_alloc.
Definition: class.c:187
VALUE rb_obj_frozen_p(VALUE obj)
Definition: object.c:1103
#define rb_obj_instance_variables(object)
Definition: generator.h:21
VALUE rb_eArgError
Definition: error.c:549
st_index_t rb_ivar_count(VALUE)
Definition: variable.c:1302
static ID cmp
Definition: compar.c:16
#define NUM2LONG(x)
Definition: ruby.h:600
#define T_MASK
Definition: md5.c:131
#define RUBY_DTRACE_OBJECT_CREATE(arg0, arg1, arg2)
Definition: probes.h:40
#define FL_PROMOTED
Definition: ruby.h:1135
VALUE rb_any_to_s(VALUE obj)
Definition: object.c:453
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1127
char ** argv
Definition: ruby.c:132
#define DBL2NUM(dbl)
Definition: ruby.h:815
#define ISSPACE(c)
Definition: ruby.h:1770
VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
Definition: class.c:377
#define StringValue(v)
Definition: ruby.h:539
VALUE rb_obj_is_instance_of(VALUE obj, VALUE c)
Definition: object.c:616
VALUE rb_cBasicObject
Definition: object.c:28
static VALUE rb_module_s_alloc(VALUE klass)
Definition: object.c:1674
#define CLASS_OR_MODULE_P(obj)
Definition: object.c:48
VALUE rb_cData
Definition: object.c:33