Class: Rubies::RandomDataStructure
- Inherits:
-
Object
- Object
- Rubies::RandomDataStructure
- Defined in:
- lib/rubies/random_data_structure.rb
Instance Attribute Summary collapse
-
#data_structure ⇒ Object
readonly
Returns the value of attribute data_structure.
Instance Method Summary collapse
- #all_values ⇒ Object
- #generate ⇒ Object
-
#initialize ⇒ RandomDataStructure
constructor
A new instance of RandomDataStructure.
Constructor Details
#initialize ⇒ RandomDataStructure
Returns a new instance of RandomDataStructure.
9 10 11 12 |
# File 'lib/rubies/random_data_structure.rb', line 9 def initialize @data_structure = Array.new @all_values = Array.new end |
Instance Attribute Details
#data_structure ⇒ Object (readonly)
Returns the value of attribute data_structure.
7 8 9 |
# File 'lib/rubies/random_data_structure.rb', line 7 def data_structure @data_structure end |
Instance Method Details
#all_values ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rubies/random_data_structure.rb', line 24 def all_values values = Array.new if @data_structure.is_a? Hash values = @data_structure.values elsif @data_structure.flatten.first.is_a? Fixnum values = @data_structure.flatten else @data_structure.each do |hash| hash.deep_traverse { |_path, value| values << value } end end values.flatten end |
#generate ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/rubies/random_data_structure.rb', line 14 def generate combo = Array.new rand(1..3).times do combo << RandomHash.new.hash_three end random_hash = RandomHash.new.generate random_array = RandomArray.new.generate @data_structure = [combo, random_hash, random_array].sample end |