Commits

Jasper Van der Jeugt committed dd557b6 Merge

Merge pull request #2 from nudded/patch-2

Ruby fold benchmark: Added idiomatic way of dividing array into parts.

  • Participants
  • Parent commits ec44468, efa1e98

Comments (0)

Files changed (1)

File tests/benchmarks/ruby/fold.rb

 # Fold a single paragraph to the desired width
 def fold_paragraph(paragraph, max_width)
   # Gradually build our output
-  str = paragraph.first
+  str, *rest = paragraph
   width = str.length
 
-  paragraph.drop(1).each do |word|
+  rest.each do |word|
     if width + word.length + 1 <= max_width
       str << ' ' << word
       width += word.length + 1