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