Class: RandomArray

Inherits:
Array
  • Object
show all
Defined in:
lib/rubies.rb

Instance Method Summary collapse

Constructor Details

#initializeRandomArray

Returns a new instance of RandomArray.



91
92
93
# File 'lib/rubies.rb', line 91

def initialize
  @ds = Array.new
end

Instance Method Details

#generateObject



109
110
111
112
# File 'lib/rubies.rb', line 109

def generate
  depth = rand(0..3)
  nesting_array.flatten(depth)
end

#mini_arrayObject



95
96
97
# File 'lib/rubies.rb', line 95

def mini_array
  (-1_000..1_000).sort_by { rand }.sample 3
end

#nesting_arrayObject



99
100
101
102
103
104
105
106
107
# File 'lib/rubies.rb', line 99

def nesting_array
  rand(1..3).times do
    @ds << mini_array
  end
  @ds.each do |array|
    array << mini_array
  end
  @ds
end