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