File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -295,6 +295,20 @@ def intersection(*values)
295
295
__with__ ( @__value__ . intersection ( *values ) )
296
296
end
297
297
298
+ def join ( ...)
299
+ @__value__ . join ( ...)
300
+ end
301
+
302
+ def keep_if ( ...)
303
+ return_value = @__value__ . keep_if ( ...)
304
+ case return_value
305
+ when Array
306
+ self
307
+ else
308
+ return_value
309
+ end
310
+ end
311
+
298
312
def last ( ...)
299
313
@__value__ . last ( ...)
300
314
end
Original file line number Diff line number Diff line change 354
354
expect ( intersection . to_a ) == [ 2 ]
355
355
end
356
356
357
+ test "#join joins the elements into a string" do
358
+ array = Literal ::Array ( Integer ) . new ( 1 , 2 , 3 )
359
+
360
+ expect ( array . join ( ", " ) ) == "1, 2, 3"
361
+ expect ( array . join ) == "123"
362
+ end
363
+
364
+ test "#keep_if keeps elements that match the block" do
365
+ array = Literal ::Array ( Integer ) . new ( 1 , 2 , 3 )
366
+
367
+ expect ( ( array . keep_if { |i | i > 1 } ) . to_a ) == [ 2 , 3 ]
368
+ end
369
+
370
+ test "#keep_if returns an enumerator if no block is given" do
371
+ array = Literal ::Array ( Integer ) . new ( 1 , 2 , 3 )
372
+
373
+ expect ( array . keep_if . class . name ) == "Enumerator"
374
+ end
375
+
357
376
test "#replace replaces with passed in array" do
358
377
array = Literal ::Array ( Integer ) . new ( 1 , 2 , 3 )
359
378
You can’t perform that action at this time.
0 commit comments