Module: FFaker::ArrayUtils

Defined in:
lib/ffaker/utils/array_utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.const_array(argument) ⇒ Object



3
4
5
6
7
# File 'lib/ffaker/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) ⇒ Object



19
20
21
22
23
# File 'lib/ffaker/utils/array_utils.rb', line 19

def self.freeze_all(array)
  array.each(&:freeze)
  array.freeze
  array
end

.rand(array) ⇒ Object



14
15
16
17
# File 'lib/ffaker/utils/array_utils.rb', line 14

def self.rand(array)
  warn '[ArrayUtils.rand] is deprecated. Please use the Array#sample method'
  array.sample
end

.random_pick(array, n) ⇒ Object



9
10
11
12
# File 'lib/ffaker/utils/array_utils.rb', line 9

def self.random_pick(array, n)
  warn '[ArrayUtils.random_pick] is deprecated. Please use the Array#sample method'
  array.sample(n)
end

.shuffle(array) ⇒ Object



25
26
27
# File 'lib/ffaker/utils/array_utils.rb', line 25

def self.shuffle(array)
  array.sort_by { Kernel.rand }
end

Instance Method Details

#freeze_allObject



39
40
41
# File 'lib/ffaker/utils/array_utils.rb', line 39

def freeze_all
  ArrayUtils.freeze_all(self)
end

#randObject



34
35
36
37
# File 'lib/ffaker/utils/array_utils.rb', line 34

def rand
  warn '[ArrayUtils#rand] is deprecated. Please use the Array#sample method'
  sample
end

#random_pick(n) ⇒ Object



29
30
31
32
# File 'lib/ffaker/utils/array_utils.rb', line 29

def random_pick(n)
  warn '[ArrayUtils#random_pick] is deprecated. Please use the Array#sample method'
  sample(n)
end

#shuffleObject



43
44
45
# File 'lib/ffaker/utils/array_utils.rb', line 43

def shuffle
  ArrayUtils.shuffle(self)
end