Class: Array

Inherits:
Object show all
Defined in:
lib/ext_core.rb

Overview

Some extentions to the core Array class

Constant Summary collapse

DEFAULT_GENERATIVE_TYPES =
[
    Integer,
    String,
    Float,
    FalseClass,
    TrueClass,
    NilClass
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.generate(min: 0, max: 30, type: nil) ⇒ Object

Randomly generate an Array



105
106
107
108
109
110
111
112
113
# File 'lib/ext_core.rb', line 105

def self.generate(min: 0, max: 30, type: nil)
  (0..Faker::Number.between(min, max)).map do
    if type.nil?
      DEFAULT_GENERATIVE_TYPES.sample.generate
    else
      type.generate
    end
  end
end

Instance Method Details

#generateArray

Randomly generate an Array from an Array instance, use the values of the array as generators.

Examples:

[Integer, Float, String].generate => [2341234, 2.24, "asdfawqsafdrawdsfasds"]

Returns:



121
122
123
# File 'lib/ext_core.rb', line 121

def generate
  map(&:generate)
end