Class: FairRandom::Box
- Inherits:
-
Object
- Object
- FairRandom::Box
- Defined in:
- lib/fair_random.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(element_type_count, box_capacity) ⇒ Box
constructor
A new instance of Box.
- #next ⇒ Object
-
#to_poro ⇒ Object
Convert to PORO(Plain Old Ruby Object) for serialize.
Constructor Details
#initialize(element_type_count, box_capacity) ⇒ Box
Returns a new instance of Box.
5 6 7 8 9 10 |
# File 'lib/fair_random.rb', line 5 def initialize(element_type_count, box_capacity) raise ArgumentError if box_capacity % element_type_count != 0 @element_type_count = element_type_count @box_capacity = box_capacity reset_contents end |
Class Method Details
.from_poro(poro) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/fair_random.rb', line 28 def self.from_poro(poro) instance = new(poro['type_count'], poro['box_capacity']) instance.instance_eval do @contents = poro['contents'] end instance end |
Instance Method Details
#next ⇒ Object
12 13 14 15 16 17 |
# File 'lib/fair_random.rb', line 12 def next reset_contents if @index >= @contents.size c = @contents[@index] @index += 1 c end |
#to_poro ⇒ Object
Convert to PORO(Plain Old Ruby Object) for serialize.
20 21 22 23 24 25 26 |
# File 'lib/fair_random.rb', line 20 def to_poro { 'type_count' => @element_type_count, 'box_capacity' => @box_capacity, 'contents' => @contents, } end |