summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS.md20
-rw-r--r--object.c56
-rw-r--r--spec/ruby/core/kernel/inspect_spec.rb30
-rw-r--r--test/ruby/test_object.rb13
4 files changed, 111 insertions, 8 deletions
@@ -14,6 +14,26 @@ Note that each entry is kept to a minimum, see links for details.
Note: We're only listing outstanding class updates.
* Binding
* `Binding#local_variables` does no longer include numbered parameters.
@@ -83,6 +83,7 @@ static VALUE rb_cFalseClass_to_s;
#define id_init_dup idInitialize_dup
#define id_const_missing idConst_missing
#define id_to_f idTo_f
#define CLASS_OR_MODULE_P(obj) \
(!SPECIAL_CONST_P(obj) && \
@@ -733,11 +734,17 @@ rb_inspect(VALUE obj)
static int
inspect_i(ID id, VALUE value, st_data_t a)
{
- VALUE str = (VALUE)a;
/* need not to show internal data */
if (CLASS_OF(value) == 0) return ST_CONTINUE;
if (!rb_is_instance_id(id)) return ST_CONTINUE;
if (RSTRING_PTR(str)[0] == '-') { /* first element */
RSTRING_PTR(str)[0] = '#';
rb_str_cat2(str, " ");
@@ -752,13 +759,15 @@ inspect_i(ID id, VALUE value, st_data_t a)
}
static VALUE
-inspect_obj(VALUE obj, VALUE str, int recur)
{
if (recur) {
rb_str_cat2(str, " ...");
}
else {
- rb_ivar_foreach(obj, inspect_i, str);
}
rb_str_cat2(str, ">");
RSTRING_PTR(str)[0] = '#';
@@ -791,17 +800,47 @@ inspect_obj(VALUE obj, VALUE str, int recur)
* end
* end
* Bar.new.inspect #=> "#<Bar:0x0300c868 @bar=1>"
*/
static VALUE
rb_obj_inspect(VALUE obj)
{
- if (rb_ivar_count(obj) > 0) {
- VALUE str;
VALUE c = rb_class_name(CLASS_OF(obj));
-
- str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void*)obj);
- return rb_exec_recursive(inspect_obj, obj, str);
}
else {
return rb_any_to_s(obj);
@@ -4600,6 +4639,7 @@ void
Init_Object(void)
{
id_dig = rb_intern_const("dig");
InitVM(Object);
}
@@ -28,4 +28,34 @@ describe "Kernel#inspect" do
end
obj.inspect.should be_kind_of(String)
end
end
@@ -950,6 +950,19 @@ class TestObject < Test::Unit::TestCase
assert_match(/\bInspect\u{3042}:.* @\u{3044}=42\b/, x.inspect)
x.instance_variable_set("@\u{3046}".encode(Encoding::EUC_JP), 6)
assert_match(/@\u{3046}=6\b/, x.inspect)
end
def test_singleton_methods