Module: FFaker::ArrayUtils

Extended by:
RandomUtils
Defined in:
lib/ffaker/utils/array_utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RandomUtils

fetch_sample

Class Method Details

.const_array(argument) ⇒ Object


6
7
8
9
10
# File 'lib/ffaker/utils/array_utils.rb', line 6

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


22
23
24
25
26
# File 'lib/ffaker/utils/array_utils.rb', line 22

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

.rand(array) ⇒ Object


17
18
19
20
# File 'lib/ffaker/utils/array_utils.rb', line 17

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

.random_pick(array, n) ⇒ Object


12
13
14
15
# File 'lib/ffaker/utils/array_utils.rb', line 12

def self.random_pick(array, n)
  warn '[ArrayUtils.random_pick] is deprecated. Please use the ModuleUtils#fetch_sample method'
  fetch_sample(array, count: n)
end

.shuffle(array) ⇒ Object


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

def self.shuffle(array)
  array.sort_by { FFaker::Random.rand }
end

Instance Method Details

#freeze_allObject


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

def freeze_all
  ArrayUtils.freeze_all(self)
end

#randObject


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

def rand
  warn '[ArrayUtils#rand] is deprecated. Please use the ModuleUtils#fetch_sample method'
  ArrayUtils.rand(self)
end

#random_pick(n) ⇒ Object


32
33
34
35
# File 'lib/ffaker/utils/array_utils.rb', line 32

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

#shuffleObject


46
47
48
# File 'lib/ffaker/utils/array_utils.rb', line 46

def shuffle
  ArrayUtils.shuffle(self)
end