Sha256: 5f9bc3b63a587fc913e0169c96a3b7fe336dc06ca55f185c17c9ac44684ca7b6

Contents?: true

Size: 729 Bytes

Versions: 6

Compression:

Stored size: 729 Bytes

Contents

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

    def self.random_pick(array, n)
      indexes = (0...array.length).sort_by{Kernel.rand}[0...n]
      indexes.map { |n| array[n].dup }
    end

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

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

    def random_pick(n)
      ArrayUtilities.random_pick(self, n)
    end

    def freeze_all
      ArrayUtilities.freeze_all(self)
    end

    def shuffle
      ArrayUtilities.shuffle(self)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
data_maker-2.2.3 lib/data_maker/utilities/array_utilities.rb
data_maker-2.1.3 lib/data_maker/utilities/array_utilities.rb
data_maker-2.1.2 lib/data_maker/utilities/array_utilities.rb
data_maker-2.1.1 lib/data_maker/utilities/array_utilities.rb
data_maker-2.0.1 lib/data_maker/utilities/array_utilities.rb
data_maker-2.0.0 lib/data_maker/utilities/array_utilities.rb