Class | Array |
In: |
lib/array.rb
|
Parent: | Object |
Extensions to the Array class. Very simple.
merge arr into a random position into the current array.
['a','b','c'].merge_randomly(['d','e'])
# File lib/array.rb, line 19 19: def merge_randomly arr 20: # get rid of blank items (compact doesn't handle '') 21: arr = arr.reject{|x| x.nil? || x == ''} 22: rand_pos = rand(self.length) 23: self[0..rand_pos] | arr | self[rand_pos..self.length] 24: end