Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/dsl/monkeypatches.rb,
lib/dsl/monkeypatches.rb

Overview

Enchancement of Array class to generate random array of the given size. The array elements are instances of the samples given. E. g. by default, there is an array of strings and fixnums produced.

Instance Method Summary collapse

Instance Method Details

#(size: 64, samples: ["", 1000]) ⇒ Array Also known as: any

Generates random sample of Array.

Examples:

To create an array of three string elements:

[""]. size: 3
# ⇒ [
#   [0] " пт64AVAэеыGN еCйдчDLFUL еPTюQL ",
#   [1] "лW1O Cи 4TZ Yиз моBи2 AзмсU5г о ",
#   [2] "70ZIзQOMXC0нXLPMкGдлэY7Bщ7Eх ой4"
# ]

Parameters:

  • size (Fixnum) (defaults to: 64)

    the size of the sample array to generate.

  • samples (Array) (defaults to: ["", 1000])

    the array of samples used to generate the sample array.

Returns:

  • (Array)

    the array of the given length, consisting of random elements from the given set.



106
107
108
109
# File 'lib/dsl/monkeypatches.rb', line 106

def (size: 64, samples: ["", 1000])
  samples = self unless self.empty?
  [].tap { |v| size.times { v << ::Kernel::random(:samples => samples) } }
end