File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -167,3 +167,42 @@ def h.to_hash; {:b => 2, :c => 3}; end
167
167
usascii_hash . keys . first . encoding . should == Encoding ::US_ASCII
168
168
end
169
169
end
170
+
171
+ describe "The ** operator" do
172
+ it "makes a copy when calling a method taking a keyword rest argument" do
173
+ def m ( **h )
174
+ h . delete ( :one ) ; h
175
+ end
176
+
177
+ h = { one : 1 , two : 2 }
178
+ m ( **h ) . should == { two : 2 }
179
+ m ( **h ) . should_not . equal? ( h )
180
+ h . should == { one : 1 , two : 2 }
181
+ end
182
+
183
+ ruby_version_is "" ..."3.0" do
184
+ it "makes a caller-side copy when calling a method taking a positional Hash" do
185
+ def m ( h )
186
+ h . delete ( :one ) ; h
187
+ end
188
+
189
+ h = { one : 1 , two : 2 }
190
+ m ( **h ) . should == { two : 2 }
191
+ m ( **h ) . should_not . equal? ( h )
192
+ h . should == { one : 1 , two : 2 }
193
+ end
194
+ end
195
+
196
+ ruby_version_is "3.0" do
197
+ it "does not copy when calling a method taking a positional Hash" do
198
+ def m ( h )
199
+ h . delete ( :one ) ; h
200
+ end
201
+
202
+ h = { one : 1 , two : 2 }
203
+ m ( **h ) . should == { two : 2 }
204
+ m ( **h ) . should . equal? ( h )
205
+ h . should == { two : 2 }
206
+ end
207
+ end
208
+ end
Original file line number Diff line number Diff line change
1
+ fails:The ** operator makes a caller-side copy when calling a method taking a positional Hash
You can’t perform that action at this time.
0 commit comments