module Faker::ArrayUtils
Public Class Methods
const_array(argument)
click to toggle source
# File lib/ffakerer/utils/array_utils.rb, line 3 def self.const_array(argument) array = argument.is_a?(Array) ? argument : argument.to_a array.extend ArrayUtils freeze_all(array) end
freeze_all(array)
click to toggle source
# File lib/ffakerer/utils/array_utils.rb, line 18 def self.freeze_all(array) array.each { |e| e.freeze } array.freeze array end
rand(array)
click to toggle source
# File lib/ffakerer/utils/array_utils.rb, line 14 def self.rand(array) array[Kernel.rand(array.length)].dup end
random_pick(array, n)
click to toggle source
# File lib/ffakerer/utils/array_utils.rb, line 9 def self.random_pick(array, n) indexes = (0...array.length).sort_by{Kernel.rand}[0...n] indexes.map { |n| array[n].dup } end
shuffle(array)
click to toggle source
# File lib/ffakerer/utils/array_utils.rb, line 24 def self.shuffle(array) array.sort_by{Kernel.rand} end
Public Instance Methods
freeze_all()
click to toggle source
# File lib/ffakerer/utils/array_utils.rb, line 36 def freeze_all ArrayUtils.freeze_all(self) end
rand()
click to toggle source
# File lib/ffakerer/utils/array_utils.rb, line 32 def rand ArrayUtils.rand(self) end
random_pick(n)
click to toggle source
# File lib/ffakerer/utils/array_utils.rb, line 28 def random_pick(n) ArrayUtils.random_pick(self, n) end
shuffle()
click to toggle source
# File lib/ffakerer/utils/array_utils.rb, line 40 def shuffle ArrayUtils.shuffle(self) end