From: Ryan Davis Date: 2007-01-03T11:33:35+09:00 Subject: Re: Mini-RCR: Extra Argument for Array#join On Jan 1, 2007, at 8:40 AM, Trans wrote: > I wonder how this would fair. > > class Array > alias :old_join :join > def join( sep=$,, last_sep=nil ) > s = old_join(sep) > if last_sep > rsep = Regexp.escape(sep.to_s) > rlast = Regexp.escape(last.to_s) > s.sub!(/#{rsep}#{rlast}$/,"#{last_sep}#{last}") > end > return s > end > end > > Sorry, the bencmark script wasn't posted and I didn't feel like > recreating it. % ./blah.rb 1_000_000 # of iterations = 1000000 user system total real null_time 0.140000 0.000000 0.140000 ( 0.139480) ryan 19.760000 0.020000 19.780000 ( 19.810269) trans 21.290000 0.040000 21.330000 ( 21.398592) Loaded suite ./blah Started .... Finished in 0.001109 seconds. 4 tests, 24 assertions, 0 failures, 0 errors