Module: ZFaker::ArrayUtils
- Defined in:
- lib/zfaker/utils/array_utils.rb
Overview
Module ArrayUtils
Class Method Summary collapse
- .const_array(argument) ⇒ Object
- .freeze_all(array) ⇒ Object
- .rand(array) ⇒ Object
- .random_pick(array, n) ⇒ Object
- .shuffle(array) ⇒ Object
Instance Method Summary collapse
Class Method Details
.const_array(argument) ⇒ Object
4 5 6 7 8 |
# File 'lib/zfaker/utils/array_utils.rb', line 4 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
20 21 22 23 24 |
# File 'lib/zfaker/utils/array_utils.rb', line 20 def self.freeze_all(array) array.each(&:freeze) array.freeze array end |
.rand(array) ⇒ Object
15 16 17 18 |
# File 'lib/zfaker/utils/array_utils.rb', line 15 def self.rand(array) warn '[ArrayUtils.rand] is deprecated. Please use the Array#sample method' array.sample end |
.random_pick(array, n) ⇒ Object
10 11 12 13 |
# File 'lib/zfaker/utils/array_utils.rb', line 10 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
26 27 28 |
# File 'lib/zfaker/utils/array_utils.rb', line 26 def self.shuffle(array) array.sort_by { Kernel.rand } end |
Instance Method Details
#freeze_all ⇒ Object
40 41 42 |
# File 'lib/zfaker/utils/array_utils.rb', line 40 def freeze_all ArrayUtils.freeze_all(self) end |
#rand ⇒ Object
35 36 37 38 |
# File 'lib/zfaker/utils/array_utils.rb', line 35 def rand warn '[ArrayUtils#rand] is deprecated. Please use the Array#sample method' sample end |
#random_pick(n) ⇒ Object
30 31 32 33 |
# File 'lib/zfaker/utils/array_utils.rb', line 30 def random_pick(n) warn '[ArrayUtils#random_pick] is deprecated. Please use the Array#sample method' sample(n) end |
#shuffle ⇒ Object
44 45 46 |
# File 'lib/zfaker/utils/array_utils.rb', line 44 def shuffle ArrayUtils.shuffle(self) end |