Sha256: 4020967ab1134c634d2abcb5677fae39b3fd873b7a8cb188393391f9708574a7

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require_relative 'random_utils'

module FFakerTW
  module ArrayUtils
    extend RandomUtils

    def self.const_array(argument)
      array = argument.is_a?(Array) ? argument : argument.to_a
      array.extend ArrayUtils
      freeze_all(array)
    end

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

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

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

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

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

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

    def freeze_all
      ArrayUtils.freeze_all(self)
    end

    def shuffle
      ArrayUtils.shuffle(self)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ffakerTW-1.8.0 lib/ffakerTW/utils/array_utils.rb
ffakerTW-1.7.0 lib/ffakerTW/utils/array_utils.rb
ffakerTW-1.6.0 lib/ffakerTW/utils/array_utils.rb
ffakerTW-1.5.0 lib/ffakerTW/utils/array_utils.rb
ffakerTW-1.4.0 lib/ffakerTW/utils/array_utils.rb
ffakerTW-1.3.0 lib/ffakerTW/utils/array_utils.rb
ffakerTW-1.2.0 lib/ffakerTW/utils/array_utils.rb
ffakerTW-1.1.0 lib/ffakerTW/utils/array_utils.rb
ffakerTW-0.1.0 lib/ffakerTW/utils/array_utils.rb