Use rb_inspect instead of +PRIsVALUE for Object.inspect
In order to preserve the values when TrueClass, FalseClass or NilClass are stored in ivars
This commit is contained in:
parent
7c438328d5
commit
181d4bee5e
Notes:
git
2022-12-09 13:11:19 +00:00
4
object.c
4
object.c
@ -677,8 +677,8 @@ inspect_i(st_data_t k, st_data_t v, st_data_t a)
|
||||
else {
|
||||
rb_str_cat2(str, ", ");
|
||||
}
|
||||
rb_str_catf(str, "%"PRIsVALUE"=%+"PRIsVALUE,
|
||||
rb_id2str(id), value);
|
||||
rb_str_catf(str, "%"PRIsVALUE"=", rb_id2str(id));
|
||||
rb_str_buf_append(str, rb_inspect(value));
|
||||
|
||||
return ST_CONTINUE;
|
||||
}
|
||||
|
@ -853,6 +853,15 @@ class TestObject < Test::Unit::TestCase
|
||||
x.instance_variable_set(:@bar, 42)
|
||||
assert_match(/\A#<Object:0x\h+ (?:@foo="value", @bar=42|@bar=42, @foo="value")>\z/, x.inspect)
|
||||
|
||||
# Bug: [ruby-core:19167]
|
||||
x = Object.new
|
||||
x.instance_variable_set(:@foo, NilClass)
|
||||
assert_match(/\A#<Object:0x\h+ @foo=NilClass>\z/, x.inspect)
|
||||
x.instance_variable_set(:@foo, TrueClass)
|
||||
assert_match(/\A#<Object:0x\h+ @foo=TrueClass>\z/, x.inspect)
|
||||
x.instance_variable_set(:@foo, FalseClass)
|
||||
assert_match(/\A#<Object:0x\h+ @foo=FalseClass>\z/, x.inspect)
|
||||
|
||||
# #inspect does not call #to_s anymore
|
||||
feature6130 = '[ruby-core:43238]'
|
||||
x = Object.new
|
||||
|
Loading…
x
Reference in New Issue
Block a user