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