Skip to content

Commit 65f9c4a

Browse files
havenwoodnobu
authored andcommitted
Drop memberless Data/Struct#inspect trailing space
Anonymous memberless Structs and Data were returning `#<struct >` and `#<data >` with a trailing space. Now they return `#<struct>` and `#<data>` to match attrless class behavior and look a bit more compact.
1 parent b6463d5 commit 65f9c4a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

struct.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ inspect_struct(VALUE s, VALUE prefix, int recur)
981981
char first = RSTRING_PTR(cname)[0];
982982

983983
if (recur || first != '#') {
984+
rb_str_cat2(str, " ");
984985
rb_str_append(str, cname);
985986
}
986987
if (recur) {
@@ -997,7 +998,7 @@ inspect_struct(VALUE s, VALUE prefix, int recur)
997998
if (i > 0) {
998999
rb_str_cat2(str, ", ");
9991000
}
1000-
else if (first != '#') {
1001+
else {
10011002
rb_str_cat2(str, " ");
10021003
}
10031004
slot = RARRAY_AREF(members, i);
@@ -1031,7 +1032,7 @@ inspect_struct(VALUE s, VALUE prefix, int recur)
10311032
static VALUE
10321033
rb_struct_inspect(VALUE s)
10331034
{
1034-
return rb_exec_recursive(inspect_struct, s, rb_str_new2("#<struct "));
1035+
return rb_exec_recursive(inspect_struct, s, rb_str_new2("#<struct"));
10351036
}
10361037

10371038
/*
@@ -1910,7 +1911,7 @@ rb_data_with(int argc, const VALUE *argv, VALUE self)
19101911
static VALUE
19111912
rb_data_inspect(VALUE s)
19121913
{
1913-
return rb_exec_recursive(inspect_struct, s, rb_str_new2("#<data "));
1914+
return rb_exec_recursive(inspect_struct, s, rb_str_new2("#<data"));
19141915
}
19151916

19161917
/*

test/ruby/test_data.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def test_memberless
259259
assert_equal(klass.new, test)
260260
assert_not_equal(Data.define.new, test)
261261

262-
assert_equal('#<data >', test.inspect)
262+
assert_equal('#<data>', test.inspect)
263263
assert_equal([], test.members)
264264
assert_equal({}, test.to_h)
265265
assert_predicate(test, :frozen?)

0 commit comments

Comments
 (0)