File tree Expand file tree Collapse file tree 4 files changed +25
-6
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 4 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ Compatibility:
79
79
* ` Kernel#exit! ` , killing Fibers and internal errors do not run code in ` ensure ` clauses anymore, the same as CRuby (@eregon ).
80
80
* Implement ` UnboundMethod#original_name ` (@paracycle , @nirvdrum ).
81
81
* Implement ` Thread#native_thread_id ` method (#2733 , @horakivo ).
82
+ * Modify ` Struct#{inspect,to_s} ` to match MRI when the struct is nested inside of an anonymous class or module (@st0012 , @nirvdrum ).
82
83
83
84
Performance:
84
85
Original file line number Diff line number Diff line change 3
3
require_relative 'shared/inspect'
4
4
5
5
describe "Struct#inspect" do
6
- it "returns a string representation showing members and values" do
7
- car = StructClasses ::Car . new ( 'Ford' , 'Ranger' )
8
- car . inspect . should == '#<struct StructClasses::Car make="Ford", model="Ranger", year=nil>'
9
- end
10
-
11
6
it_behaves_like :struct_inspect , :inspect
12
7
end
Original file line number Diff line number Diff line change 1
1
describe :struct_inspect , shared : true do
2
+ it "returns a string representation showing members and values" do
3
+ car = StructClasses ::Car . new ( 'Ford' , 'Ranger' )
4
+ car . send ( @method ) . should == '#<struct StructClasses::Car make="Ford", model="Ranger", year=nil>'
5
+ end
6
+
2
7
it "returns a string representation without the class name for anonymous structs" do
3
8
Struct . new ( :a ) . new ( "" ) . send ( @method ) . should == '#<struct a="">'
4
9
end
10
+
11
+ it "returns a string representation without the class name for structs nested in anonymous classes" do
12
+ c = Class . new
13
+ c . class_eval <<~DOC
14
+ class Foo < Struct.new(:a); end
15
+ DOC
16
+
17
+ c ::Foo . new ( "" ) . send ( @method ) . should == '#<struct a="">'
18
+ end
19
+
20
+ it "returns a string representation without the class name for structs nested in anonymous modules" do
21
+ m = Module . new
22
+ m . module_eval <<~DOC
23
+ class Foo < Struct.new(:a); end
24
+ DOC
25
+
26
+ m ::Foo . new ( "" ) . send ( @method ) . should == '#<struct a="">'
27
+ end
5
28
end
Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ def to_s
147
147
148
148
name = self . class . name
149
149
150
- if Primitive . nil? ( name ) || name . empty?
150
+ if Primitive . nil? ( name ) || name . empty? || name [ 0 ] == '#'
151
151
return "#<struct #{ values . join ( ', ' ) } >"
152
152
else
153
153
return "#<struct #{ self . class . name } #{ values . join ( ', ' ) } >"
You can’t perform that action at this time.
0 commit comments