Class: RandomArray
- Inherits:
-
Array
- Object
- Array
- RandomArray
- Defined in:
- lib/rubies.rb
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize ⇒ RandomArray
constructor
A new instance of RandomArray.
- #mini_array ⇒ Object
- #nesting_array ⇒ Object
Constructor Details
#initialize ⇒ RandomArray
Returns a new instance of RandomArray.
91 92 93 |
# File 'lib/rubies.rb', line 91 def initialize @ds = Array.new end |
Instance Method Details
#generate ⇒ Object
109 110 111 112 |
# File 'lib/rubies.rb', line 109 def generate depth = rand(0..3) nesting_array.flatten(depth) end |
#mini_array ⇒ Object
95 96 97 |
# File 'lib/rubies.rb', line 95 def mini_array (-1_000..1_000).sort_by { rand }.sample 3 end |
#nesting_array ⇒ Object
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 |