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