Module: Drx::Core
- Defined in:
- ext/drx_core.c
Constant Summary collapse
- FL_SINGLETON =
INT2FIX(FL_SINGLETON)
- T_OBJECT =
INT2FIX(T_OBJECT)
- T_CLASS =
INT2FIX(T_CLASS)
- T_ICLASS =
INT2FIX(T_ICLASS)
- T_MODULE =
INT2FIX(T_MODULE)
Class Method Summary collapse
-
.get_address(obj) ⇒ Object
Returns the object's "id".
-
.get_flags(obj) ⇒ Object
Returns an object's flags.
-
.get_iv_tbl(obj) ⇒ Object
Gets the iv_tbl of the object, as a Ruby hash.
-
.get_ivar(obj, var_name) ⇒ Object
Extracts one varibale from an object iv_tbl.
-
.get_klass(obj) ⇒ Object
Returns an object's klass.
-
.get_m_tbl(obj) ⇒ Object
Gets the m_tbl of a class.
-
.get_super(obj) ⇒ Object
Returns a class's super.
-
.get_type(obj) ⇒ Object
Gets the Ruby's engine type of a variable.
-
.Drx::Core::locate_method(Date, "to_s") ⇒ Object
Locates the filename and line-number where a method was defined.
Class Method Details
.get_address(obj) ⇒ Object
Returns the object's "id".
This is an alternative to Object#id because the latter doesn't work for T_ICLASS.
135 136 137 138 |
# File 'ext/drx_core.c', line 135 static VALUE t_get_address(VALUE self, VALUE obj) { return INT2NUM(obj); } |
.get_flags(obj) ⇒ Object
Returns an object's flags.
97 98 99 100 |
# File 'ext/drx_core.c', line 97 static VALUE t_get_flags(VALUE self, VALUE obj) { return INT2NUM(RBASIC(obj)->flags); } |
.get_iv_tbl(obj) ⇒ Object
Gets the iv_tbl of the object, as a Ruby hash.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'ext/drx_core.c', line 32 static VALUE t_get_iv_tbl(VALUE self, VALUE obj) { VALUE hash; hash = rb_hash_new(); if (TYPE(obj) != T_OBJECT && TYPE(obj) != T_CLASS && TYPE(obj) != T_ICLASS && TYPE(obj) != T_MODULE) { rb_raise(rb_eTypeError, "Only T_OBJECT/T_CLASS/T_MODULE is expected as the argument (got %d)", TYPE(obj)); } #ifdef RUBY_1_8 if (ROBJECT(obj)->iv_tbl) { st_foreach(ROBJECT(obj)->iv_tbl, record_var, (st_data_t)hash); } #else rb_ivar_foreach(obj, record_var, hash); #endif return hash; } |
.get_ivar(obj, var_name) ⇒ Object
Extracts one varibale from an object iv_tbl.
55 56 57 58 59 60 61 62 63 |
# File 'ext/drx_core.c', line 55 static VALUE t_get_ivar(VALUE self, VALUE obj, VALUE var_name) { const char *c_name; if (TYPE(obj) != T_OBJECT && TYPE(obj) != T_CLASS && TYPE(obj) != T_ICLASS && TYPE(obj) != T_MODULE) { rb_raise(rb_eTypeError, "Only T_OBJECT/T_CLASS/T_MODULE is expected as the argument (got %d)", TYPE(obj)); } c_name = StringValuePtr(var_name); return rb_iv_get(obj, c_name); } |
.get_klass(obj) ⇒ Object
Returns an object's klass.
In contrast to Object#class, this function doesn't skip singletons and T_ICLASS.
88 89 90 91 92 |
# File 'ext/drx_core.c', line 88 static VALUE t_get_klass(VALUE self, VALUE obj) { return CLASS_OF(obj); // Note: we can't simply do 'RBASIC(obj)->klass', because obj may be an 'immediate'. } |
.get_m_tbl(obj) ⇒ Object
Gets the m_tbl of a class.
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'ext/drx_core.c', line 116 static VALUE t_get_m_tbl(VALUE self, VALUE obj) { VALUE hash; if (TYPE(obj) != T_CLASS && TYPE(obj) != T_ICLASS && TYPE(obj) != T_MODULE) { rb_raise(rb_eTypeError, "Only T_CLASS/T_MODULE is expected as the argument (got %d)", TYPE(obj)); } hash = rb_hash_new(); st_foreach(RCLASS(obj)->m_tbl, record_method, (st_data_t)hash); return hash; } |
.get_super(obj) ⇒ Object
Returns a class's super.
In contrast to Class#superclass, this function doesn't skip singletons and T_ICLASS.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'ext/drx_core.c', line 70 static VALUE t_get_super(VALUE self, VALUE obj) { if (TYPE(obj) != T_CLASS && TYPE(obj) != T_ICLASS && TYPE(obj) != T_MODULE) { rb_raise(rb_eTypeError, "Only T_CLASS/T_MODULE is expected as the argument (got %d)", TYPE(obj)); } #ifdef RCLASS_SUPER // Ruby 1.8.7 and above have this macro. return RCLASS_SUPER(obj) ? RCLASS_SUPER(obj) : Qnil; #else return RCLASS(obj)->super ? RCLASS(obj)->super : Qnil; #endif } |
.get_type(obj) ⇒ Object
Gets the Ruby's engine type of a variable.
16 17 18 19 |
# File 'ext/drx_core.c', line 16 static VALUE t_get_type(VALUE self, VALUE obj) { return INT2NUM(TYPE(obj)); } |
.Drx::Core::locate_method(Date, "to_s") ⇒ Object
Locates the filename and line-number where a method was defined.
Returns one of:
- [ "/path/to/file.rb", 89 ]
- A string of the form "
" if the method isn't written in Ruby. Possibilities are , , , and more. - raises NameError if the method doesn't exist.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'ext/drx_core.c', line 237 static VALUE t_locate_method(VALUE self, VALUE obj, VALUE method_name) { const char *c_name; NODE *method_node; if (TYPE(obj) != T_CLASS && TYPE(obj) != T_ICLASS && TYPE(obj) != T_MODULE) { rb_raise(rb_eTypeError, "Only T_CLASS/T_MODULE is expected as the argument (got %d)", TYPE(obj)); } c_name = StringValuePtr(method_name); ID id = rb_intern(c_name); if (RCLASS(obj)->m_tbl && st_lookup(RCLASS(obj)->m_tbl, id, (st_data_t *)&method_node)) { return t_do_locate_method(method_node); } else { rb_raise(rb_eNameError, "method not found"); } } |