Class: Enumerator
Instance Attribute Summary collapse
-
#__memo__ ⇒ Object
Returns the value of attribute __memo__.
-
#__memo_instance__ ⇒ Object
Returns the value of attribute memo_instance.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#__memo__ ⇒ Object
Returns the value of attribute __memo__.
18 19 20 |
# File 'lib/abstractivator/enumerator_ext.rb', line 18 def __memo__ @__memo__ end |
#__memo_instance__ ⇒ Object
Returns the value of attribute memo_instance.
18 19 20 |
# File 'lib/abstractivator/enumerator_ext.rb', line 18 def __memo_instance__ @__memo_instance__ end |
Class Method Details
.unfold(state) {|state| ... } ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/abstractivator/enumerator_ext.rb', line 5 def self.unfold(state) raise 'block is required' unless block_given? Enumerator.new do |y| unless state.nil? loop do next_value, state = yield(state) break if state.nil? y << next_value end end end end |
Instance Method Details
#memoized ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/abstractivator/enumerator_ext.rb', line 20 def memoized @__memo_instance__ ||= self.dup inner = __memo_instance__ inner.__memo__ ||= [] Enumerator.new do |y| i = 0 loop do inner.__memo__ << inner.next while inner.__memo__.size <= i y << inner.__memo__[i] i += 1 end end end |