Ruby
2.5.0dev(2017-10-22revision60238)
|
Macros | |
#define | id_for_var(obj, name, part, type) id_for_setter(obj, name, type, "`%1$s' is not allowed as "#part" "#type" variable name") |
#define | id_for_setter(obj, name, type, message) check_setter_id(obj, &(name), rb_is_##type##_id, rb_is_##type##_name, message, strlen(message)) |
#define | IMPLICIT_CONVERSIONS 7 |
Functions | |
void | rb_obj_call_init (VALUE obj, int argc, const VALUE *argv) |
Calls #initialize method of obj with the given arguments. More... | |
VALUE | rb_obj_hide (VALUE obj) |
Make the object invisible from Ruby code. More... | |
VALUE | rb_obj_reveal (VALUE obj, VALUE klass) |
Make a hidden object visible again. More... | |
VALUE | rb_obj_setup (VALUE obj, VALUE klass, VALUE type) |
Fills common (RBasic ) fields in obj. More... | |
VALUE | rb_equal (VALUE obj1, VALUE obj2) |
call-seq: obj === other -> true or false More... | |
int | rb_eql (VALUE obj1, VALUE obj2) |
Determines if obj1 and obj2 are equal in terms of Object::eql ?. More... | |
VALUE | rb_obj_hash (VALUE obj) |
VALUE | rb_class_real (VALUE cl) |
Looks up the nearest ancestor of cl, skipping singleton classes or module inclusions. More... | |
VALUE | rb_obj_class (VALUE obj) |
call-seq: obj.class -> class More... | |
VALUE | rb_obj_clone (VALUE obj) |
:nodocAlmost same asObject::clone ++ More... | |
VALUE | rb_obj_dup (VALUE obj) |
call-seq: obj.dup -> an_object More... | |
VALUE | rb_obj_init_copy (VALUE obj, VALUE orig) |
:nodoc:Default implementation of#initialize_copy More... | |
VALUE | rb_obj_init_dup_clone (VALUE obj, VALUE orig) |
:nodoc:Default implementation of#initialize_dup and #initialize_clone More... | |
VALUE | rb_any_to_s (VALUE obj) |
call-seq: obj.to_s -> string More... | |
VALUE | rb_str_escape (VALUE str) |
VALUE | rb_inspect (VALUE obj) |
Convenient wrapper of Object::inspect . More... | |
VALUE | rb_obj_is_instance_of (VALUE obj, VALUE c) |
call-seq: obj.instance_of?(class) -> true or false More... | |
VALUE | rb_obj_is_kind_of (VALUE obj, VALUE c) |
call-seq: obj.is_a?(class) -> true or false obj.kind_of?(class) -> true or false More... | |
VALUE | rb_obj_tainted (VALUE obj) |
call-seq: obj.tainted? -> true or false More... | |
VALUE | rb_obj_taint (VALUE obj) |
call-seq: obj.taint -> obj More... | |
VALUE | rb_obj_untaint (VALUE obj) |
call-seq: obj.untaint -> obj More... | |
VALUE | rb_obj_untrusted (VALUE obj) |
call-seq: obj.untrusted? -> true or false More... | |
VALUE | rb_obj_untrust (VALUE obj) |
call-seq: obj.untrust -> obj More... | |
VALUE | rb_obj_trust (VALUE obj) |
call-seq: obj.trust -> obj More... | |
void | rb_obj_infect (VALUE victim, VALUE carrier) |
Convenient function to infect victim with the taintedness of carrier. More... | |
VALUE | rb_obj_freeze (VALUE obj) |
call-seq: obj.freeze -> obj More... | |
VALUE | rb_obj_frozen_p (VALUE obj) |
call-seq: obj.frozen? -> true or false More... | |
VALUE | rb_class_inherited_p (VALUE mod, VALUE arg) |
call-seq: mod <= other -> true, false, or nil More... | |
VALUE | rb_obj_alloc (VALUE klass) |
Allocates an instance of klass. More... | |
VALUE | rb_class_new_instance (int argc, const VALUE *argv, VALUE klass) |
Allocates and initializes an instance of klass. More... | |
VALUE | rb_class_superclass (VALUE klass) |
call-seq: class.superclass -> a_super_class or nil More... | |
VALUE | rb_class_get_superclass (VALUE klass) |
Returns the superclass of klass The return value might be an iclass of a module, unlike rb_class_superclass. More... | |
VALUE | rb_convert_type (VALUE val, int type, const char *tname, const char *method) |
Converts an object into another type. More... | |
VALUE | rb_check_convert_type (VALUE val, int type, const char *tname, const char *method) |
Tries to convert an object into another type. More... | |
VALUE | rb_check_to_integer (VALUE val, const char *method) |
Tries to convert val into Integer . More... | |
VALUE | rb_to_int (VALUE val) |
Converts val into Integer . More... | |
VALUE | rb_check_to_int (VALUE val) |
Tries to convert val into Integer. More... | |
VALUE | rb_Integer (VALUE val) |
Equivalent to Kernel#Integer in Ruby. More... | |
double | rb_cstr_to_dbl (const char *p, int badcheck) |
Parses a string representation of a floating point number. More... | |
double | rb_str_to_dbl (VALUE str, int badcheck) |
Parses a string representation of a floating point number. More... | |
VALUE | rb_Float (VALUE val) |
Equivalent to Kernel#Float in Ruby. More... | |
VALUE | rb_to_float (VALUE val) |
Converts a Numeric object into Float . More... | |
VALUE | rb_check_to_float (VALUE val) |
Tries to convert an object into Float . More... | |
double | rb_num2dbl (VALUE val) |
Converts a Numeric object to double . More... | |
VALUE | rb_String (VALUE val) |
Equivalent to Kernel#String in Ruby. More... | |
VALUE | rb_Array (VALUE val) |
Equivalent to Kernel#Array in Ruby. More... | |
VALUE | rb_Hash (VALUE val) |
Equivalent to Kernel#Hash in Ruby. More... | |
void | Init_Object (void) |
Variables | |
VALUE | rb_cBasicObject |
BasicObject class. More... | |
VALUE | rb_mKernel |
Kernel module. More... | |
VALUE | rb_cObject |
Object class. More... | |
VALUE | rb_cModule |
Module class. More... | |
VALUE | rb_cClass |
Class class. More... | |
VALUE | rb_cData |
Data class. More... | |
VALUE | rb_cNilClass |
NilClass class. More... | |
VALUE | rb_cTrueClass |
TrueClass class. More... | |
VALUE | rb_cFalseClass |
FalseClass class. More... | |
#define id_for_var | ( | obj, | |
name, | |||
part, | |||
type | |||
) | id_for_setter(obj, name, type, "`%1$s' is not allowed as "#part" "#type" variable name") |
void Init_Object | ( | void | ) |
Definition at line 4117 of file object.c.
References InitVM, and rb_intern_const.
call-seq: obj.to_s -> string
Returns a string representing obj. The default to_s
prints the object's class and an encoding of the object id. As a special case, the top-level object that is the initial execution context of Ruby programs returns ``main''.
Default implementation of #to_s
. ++
Definition at line 631 of file object.c.
References CLASS_OF, OBJ_INFECT, PRIsVALUE, rb_class_name(), rb_sprintf(), and rb_str_escape().
Referenced by rb_int2str(), and rb_obj_as_string_result().
Equivalent to Kernel#Array
in Ruby.
Definition at line 3592 of file object.c.
References NIL_P, rb_ary_new3, rb_check_array_type(), rb_check_convert_type_with_id(), and T_ARRAY.
Tries to convert an object into another type.
Calls the specified conversion method if necessary.
[in] | val | the object to be converted |
[in] | type | a value of ruby_value_type |
[in] | tname | name of the target type. only used for error messages. |
[in] | method | name of the method |
TypeError | if the conversion method returns an unexpected type of value. |
Definition at line 3006 of file object.c.
References T_DATA, TYPE, and val.
Referenced by rb_check_regexp_type(), and rb_check_to_float().
Tries to convert an object into Float
.
It calls #to_f
if necessary.
It returns Qnil
if the object is not a Numeric
or #to_f
is not defined on the object.
Definition at line 3465 of file object.c.
References Qnil, rb_check_convert_type(), rb_cNumeric, rb_obj_is_kind_of(), RB_TYPE_P, T_FLOAT, and val.
Tries to convert val into Integer.
It calls #to_int
method if necessary.
[in] | val | a Ruby object |
Qnil
if #to_int
is not defined. TypeError | if #to_int returns a non-Integer object. |
Definition at line 3099 of file object.c.
References rb_check_to_integer().
Tries to convert val into Integer
.
It calls the specified conversion method if necessary.
[in] | val | a Ruby object |
[in] | method | a name of a method |
Integer
object on success, or Qnil
if no such conversion method defined. TypeError | if the conversion method returns a non-Integer object. |
Definition at line 3062 of file object.c.
References FIXNUM_P, RB_TYPE_P, T_BIGNUM, and val.
Referenced by rb_check_to_int().
Returns the superclass of klass The return value might be an iclass of a module, unlike rb_class_superclass.
Also it returns Qfalse when klass does not have a parent class.
Definition at line 2229 of file object.c.
References RCLASS.
call-seq: mod <= other -> true, false, or nil
Returns true if mod is a subclass of other or is the same as other. Returns nil
if there's no relationship between the two. (Think of the relationship in terms of the class definition:
Determines if mod inherits arg. Equivalent to Module#<=
in Ruby
[in] | mod | a Module object |
[in] | arg | another Module object or an iclass of a module |
Qtrue | if mod inherits arg, or mod equals arg |
Qfalse | if arg inherits mod |
Qnil | if otherwise ++ |
Definition at line 1827 of file object.c.
References CLASS_OR_MODULE_P, Qtrue, rb_eTypeError, rb_raise(), RB_TYPE_P, and T_ICLASS.
Allocates and initializes an instance of klass.
Equivalent to Class#new
in Ruby
[in] | argc | the number of arguments to #initialize |
[in] | argv | a pointer to an array of arguments to #initialize |
[in] | klass | a Class object |
Definition at line 2170 of file object.c.
References Check_Type, and T_CLASS.
Referenced by Init_Exception(), rb_exit(), rb_f_abort(), rb_fiddle_new_function(), rb_name_error(), rb_name_error_str(), rb_struct_alloc(), rb_syserr_new_str(), and rb_throw_obj().
Looks up the nearest ancestor of cl, skipping singleton classes or module inclusions.
It returns the cl itself if it is neither a singleton class or a module.
[in] | cl | a Class object. |
Definition at line 251 of file object.c.
References BUILTIN_TYPE, FL_SINGLETON, RBASIC, RCLASS_SUPER, and T_ICLASS.
Referenced by rb_class_name(), rb_define_class(), rb_define_class_id_under(), rb_obj_class(), rb_vm_bugreport(), and ruby_vm_special_exception_copy().
call-seq: class.superclass -> a_super_class or nil
Returns the superclass of class, or nil
.
File.superclass #=> IO IO.superclass #=> Object Object.superclass #=> BasicObject class Foo; end class Bar < Foo; end Bar.superclass #=> Foo
Returns nil when the given class does not have a parent class:
BasicObject.superclass #=> nil
Returns the superclass of klass. Equivalent to Class#superclass
in Ruby.
It skips modules.
[in] | klass | a Class object |
Qnil
if klass does not have a parent class. Definition at line 2204 of file object.c.
References Qnil, rb_cBasicObject, rb_eTypeError, rb_raise(), RB_TYPE_P, RCLASS_SUPER, and T_ICLASS.
Converts an object into another type.
Calls the specified conversion method if necessary.
[in] | val | the object to be converted |
[in] | type | a value of ruby_value_type |
[in] | tname | name of the target type. only used for error messages. |
[in] | method | name of the method |
TypeError | on failure |
Definition at line 2965 of file object.c.
Referenced by rb_numeric_quo().
double rb_cstr_to_dbl | ( | const char * | p, |
int | badcheck | ||
) |
Parses a string representation of a floating point number.
[in] | p | a string representation of a floating number |
[in] | badcheck | raises an exception on parse error if badcheck is non-zero. |
Definition at line 3208 of file object.c.
References bad, buf, DBL_DIG, errno, ISDIGIT, ISSPACE, OutOfRange, rb_eArgError, rb_invalid_str(), rb_raise(), rb_warning(), and strtod.
Referenced by rb_str_to_dbl().
call-seq: obj === other -> true or false
Case Equality – For class Object, effectively the same as calling #==
, but typically overridden by descendants to provide
Same as Object#===
, case equality. ++
Definition at line 126 of file object.c.
Referenced by rb_ary_assoc(), rb_ary_delete(), rb_ary_includes(), rb_ary_rassoc(), and rb_str_equal().
Equivalent to Kernel#Hash
in Ruby.
Definition at line 3635 of file object.c.
References NIL_P, RARRAY_LEN, rb_check_hash_type(), rb_eTypeError, rb_hash_new(), rb_obj_classname(), rb_raise(), RB_TYPE_P, and T_ARRAY.
Convenient wrapper of Object::inspect
.
Returns a human-readable string representation of obj, similarly to Object::inspect
.
Unlike Ruby-level #inspect
, it escapes characters to keep the result compatible to the default internal or external encoding. If the default internal or external encoding is ASCII compatible, the encoding of the inspected result must be compatible with it. If the default internal or external encoding is ASCII incompatible, the result must be ASCII only.
Definition at line 656 of file object.c.
References NULL, rb_default_external_encoding(), rb_default_internal_encoding(), rb_enc_asciicompat, rb_enc_get(), rb_enc_str_asciionly_p(), rb_funcallv, rb_obj_as_string(), and rb_str_escape().
Referenced by rb_p(), rb_vmdebug_debug_print_post(), and rb_vmdebug_proc_dump_raw().
Equivalent to Kernel#Integer
in Ruby.
Converts val into Integer
in a slightly more strict manner than #to_i
.
Definition at line 3148 of file object.c.
Referenced by ossl_time_split(), and value_to_generic().
double rb_num2dbl | ( | VALUE | val | ) |
Converts a Numeric
object to double
.
[in] | val | a Numeric object |
TypeError | if val is not a Numeric or it does not support conversion to a floating point number. |
Definition at line 3524 of file object.c.
References FIXNUM_P, FLONUM_P, and SPECIAL_CONST_P.
Allocates an instance of klass.
[in] | klass | a Class object |
Definition at line 2121 of file object.c.
References Check_Type, and T_CLASS.
Referenced by Init_top_self(), rb_catch(), rb_key_err_new(), rb_last_status_set(), rb_name_err_new(), rb_range_new(), and ruby_vm_special_exception_copy().
Calls #initialize
method of obj with the given arguments.
It also forwards the given block to #initialize
if given.
[in] | obj | the receiver object |
[in] | argc | the number of arguments |
[in] | argv | a pointer to the array of arguments |
Definition at line 1583 of file eval.c.
References PASS_PASSED_BLOCK_HANDLER, and rb_funcallv.
call-seq: obj.class -> class
Returns the class of obj. This method must always be called with an explicit receiver, as class
is also a reserved word in Ruby.
1.class #=> Integer
Equivalent to Object#class
in Ruby.
Returns the class of obj
, skipping singleton classes or module inclusions. ++
Definition at line 277 of file object.c.
References CLASS_OF, and rb_class_real().
Referenced by BIGNUM_1c(), rb_ary_subseq(), rb_block_to_s(), rb_check_inheritable(), rb_define_class(), rb_define_class_id_under(), rb_define_module(), rb_define_module_id_under(), rb_obj_init_copy(), rb_struct_members(), and rb_vm_bugreport().
Object::clone
++
Definition at line 475 of file object.c.
Referenced by rb_eval_string_wrap().
call-seq: obj.dup -> an_object
Produces a shallow copy of obj—the instance variables of obj are copied, but not the objects they reference. dup
copies the tainted state of obj.
This method may have class-specific behavior. If so, that behavior will be documented under the #+initialize_copy+ method of the class.
=== on dup vs clone
In general, clone
and dup
may have different semantics in descendant classes. While clone
is used to duplicate an object, including its internal state, dup
typically uses the class of the descendant object to create the new instance.
When using #dup, any modules that the object has been extended with will not be copied.
class Klass attr_accessor :str end module Foo def foo; 'foo'; end end s1 = Klass.new #=> #<Klass:0x401b3a38> s1.extend(Foo) #=> #<Klass:0x401b3a38> s1.foo #=> "foo" s2 = s1.clone #=> #<Klass:0x401b3a38> s2.foo #=> "foo" s3 = s1.dup #=> #<Klass:0x401b3a38> s3.foo #=> NoMethodError: undefined method `foo' for #<Klass:0x401b3a38>
– Equivalent to Object#dup
in Ruby ++
call-seq: obj.freeze -> obj
Prevents further modifications to obj. A RuntimeError
will be raised if modification is attempted. There is no way to unfreeze a frozen object. See also Object::frozen?
.
This method returns self.
a = [ "a", "b", "c" ] a.freeze a << "z"
produces:
prog.rb:3:in `<<': can't modify frozen Array (RuntimeError) from prog.rb:3
Objects of the following classes are always frozen: Integer,
Make the object unmodifiable. Equivalent to Object#freeze
in Ruby.
[in,out] | obj | the object to be frozen |
Definition at line 1331 of file object.c.
References OBJ_FREEZE, OBJ_FROZEN, rb_bug(), and SPECIAL_CONST_P.
Referenced by rb_ary_freeze(), rb_insns_name_array(), rb_iseq_pathobj_new(), rb_str_freeze(), and rb_vm_register_special_exception_str().
call-seq: obj.frozen? -> true or false
Returns the freeze status of obj.
a = [ "a", "b", "c" ] a.freeze #=> ["a", "b", "c"]
Determines if the object is frozen. Equivalent to Object#frozen
? in Ruby.
[in] | obj | the object to be determines |
Qtrue | if frozen |
Qfalse | if not frozen ++ |
Definition at line 1360 of file object.c.
References OBJ_FROZEN, Qfalse, and Qtrue.
Make the object invisible from Ruby code.
It is useful to let Ruby's GC manage your internal data structure – The object keeps being managed by GC, but ObjectSpace.each_object
never yields the object.
Note that the object also lose a way to call a method on it.
[in] | obj | a Ruby object |
Definition at line 72 of file object.c.
References RBASIC_CLEAR_CLASS, and SPECIAL_CONST_P.
Convenient function to infect victim with the taintedness of carrier.
It just keeps the taintedness of victim if carrier is not tainted.
[in,out] | victim | the object being infected with the taintness of carrier |
[in] | carrier | a possibly tainted object |
Definition at line 1296 of file object.c.
References OBJ_INFECT.
#initialize_copy
[in,out] | obj | the receiver being initialized |
[in] | orig | the object to be copied from. ++ |
Definition at line 590 of file object.c.
References rb_check_frozen, rb_check_trusted(), rb_eTypeError, rb_obj_class(), rb_raise(), and TYPE.
#initialize_dup
and #initialize_clone
[in,out] | obj | the receiver being initialized |
[in] | orig | the object to be dup or cloned from. ++ |
Definition at line 611 of file object.c.
References rb_funcall().
call-seq: obj.instance_of?(class) -> true or false
Returns true
if obj is an instance of the given class. See also Object::kind_of?
.
class A; end class B < A; end class C < B; end
b = B.new b.instance_of? A #=> false b.instance_of? B #=> true
Determines if obj is an instance of c.
Equivalent to Object#is_instance_of
in Ruby.
[in] | obj | the object to be determined. |
[in] | c | a Class object ++ |
call-seq: obj.is_a?(class) -> true or false obj.kind_of?(class) -> true or false
Returns true
if class is the class of obj, or if class is one of the superclasses of obj or modules included in obj.
module M; end class A include M end class B < A; end class C < B; end
b = B.new b.is_a? A #=> true b.is_a? B #=> true b.is_a? C #=> false b.is_a? M #=> true
b.kind_of? A #=> true b.kind_of? B #=> true b.kind_of? C #=> false
Determines if obj is a kind of c.
Equivalent to Object#kind_of
? in Ruby.
[in] | obj | the object to be determined |
[in] | c | a Module object. ++ |
Definition at line 842 of file object.c.
References CLASS_OF.
Referenced by ole_val2variant(), ossl_evp_get_cipherbyname(), rb_check_to_float(), rb_enumeratorize_with_size(), rb_range_values(), and rb_set_errinfo().
Make a hidden object visible again.
It is the caller's responsibility to pass the right klass which obj originally used to belong to.
Definition at line 89 of file object.c.
References RBASIC_SET_CLASS, and SPECIAL_CONST_P.
Fills common (RBasic
) fields in obj.
[in,out] | obj | a Ruby object to be set up. |
[in] | klass | obj will belong to this class. |
[in] | type | one of ruby_value_type |
Definition at line 106 of file object.c.
References RBASIC, and RBASIC_SET_CLASS.
call-seq: obj.taint -> obj
Mark the object as tainted.
Objects that are marked as tainted will be restricted from various built-in methods. This is to prevent insecure data, such as command-line arguments or strings read from Kernel::gets, from inadvertently compromising the user's system.
To check whether an object is tainted, use #tainted?.
You should only untaint a tainted object if your code has inspected it and
Marks the object as tainted. Equivalent to Object#taint
in Ruby
[in] | obj | the object to be tainted |
Definition at line 1179 of file object.c.
References OBJ_TAINT, OBJ_TAINTABLE, OBJ_TAINTED, and rb_check_frozen.
Referenced by rb_obj_untrust().
call-seq: obj.tainted? -> true or false
Returns true if the object is tainted.
Determines if obj is tainted. Equivalent to Object#tainted
? in Ruby.
[in] | obj | the object to be determined |
Qtrue | if the object is tainted |
Qfalse | if the object is not tainted |
Definition at line 1147 of file object.c.
References OBJ_TAINTED, Qfalse, and Qtrue.
Referenced by rb_obj_untrusted().
call-seq: obj.trust -> obj
Trustiness used to have independent semantics from taintedness. But now trustiness of objects is obsolete and this function behaves the same as rb_obj_untaint.
Definition at line 1281 of file object.c.
References rb_obj_untaint(), and rb_warning().
call-seq: obj.untaint -> obj
Removes the tainted mark from the object.
Removes the tainted mark from the object. Equivalent to Object#untaint
in Ruby.
[in] | obj | the object to be tainted |
Definition at line 1208 of file object.c.
References FL_TAINT, FL_UNSET, OBJ_TAINTED, and rb_check_frozen.
Referenced by rb_obj_trust().
call-seq: obj.untrust -> obj
Trustiness used to have independent semantics from taintedness. But now trustiness of objects is obsolete and this function behaves the same as rb_obj_taint.
Definition at line 1257 of file object.c.
References rb_obj_taint(), and rb_warning().
call-seq: obj.untrusted? -> true or false
Trustiness used to have independent semantics from taintedness. But now trustiness of objects is obsolete and this function behaves the same as rb_obj_tainted.
Definition at line 1234 of file object.c.
References rb_obj_tainted(), and rb_warning().
Definition at line 5737 of file string.c.
References buf, CHAR_ESC_LEN, ENCODING_GET, rb_enc_from_index(), RSTRING_END, and RSTRING_PTR.
Referenced by rb_any_to_s(), and rb_inspect().
double rb_str_to_dbl | ( | VALUE | str, |
int | badcheck | ||
) |
Parses a string representation of a floating point number.
[in] | str | a String object representation of a floating number |
[in] | badcheck | raises an exception on parse error if badcheck is non-zero. |
Definition at line 3298 of file object.c.
References ALLOCV, ALLOCV_END, len, MEMCPY, rb_cstr_to_dbl(), rb_eArgError, rb_raise(), RSTRING_LEN, RSTRING_PTR, and StringValue.
Equivalent to Kernel#String
in Ruby.
Converts val into String
by trying #to_str
at first and then trying #to_s
.
Definition at line 3560 of file object.c.
References NIL_P, rb_check_string_type(), rb_convert_type_with_id(), and T_STRING.
Converts val into Integer
.
It calls #to_int method if necessary.
[in] | val | a Ruby object |
Integer
object TypeError | on failure |
Definition at line 3084 of file object.c.
Referenced by rb_absint_singlebit_p(), rb_absint_size(), rb_integer_pack(), rb_num2fix(), and rb_num2long().
VALUE rb_cBasicObject |