Class: Quarry::EnumerableHelper
- Inherits:
-
Object
- Object
- Quarry::EnumerableHelper
- Includes:
- Enumerable
- Defined in:
- lib/quarry_rb/enumerable_helper.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each ⇒ Object
-
#initialize(data_set, container, klass, size, get_fn) ⇒ EnumerableHelper
constructor
A new instance of EnumerableHelper.
Constructor Details
#initialize(data_set, container, klass, size, get_fn) ⇒ EnumerableHelper
Returns a new instance of EnumerableHelper.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/quarry_rb/enumerable_helper.rb', line 6 def initialize(data_set, container, klass, size, get_fn) @size = container.send(size) @container = container @data_set = data_set @get_fn = get_fn @klass = klass # because of the way the Ruby GC works, it's easier to store # references to enumerated objects here than from the C++ side. # by keeping a reference to returned objects in this object, # iterated objects that shouldn't be released (e.g Examples) # won't be until the data set is released. @objects = Hash.new {|hash, index| hash[index] = @klass.new(@container.send(@get_fn, index), @data_set)} end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/quarry_rb/enumerable_helper.rb', line 4 def size @size end |
Instance Method Details
#[](index) ⇒ Object
21 22 23 24 |
# File 'lib/quarry_rb/enumerable_helper.rb', line 21 def [](index) return nil if (index < 0) || (index >= @size) @objects[index] end |
#each ⇒ Object
26 27 28 29 30 |
# File 'lib/quarry_rb/enumerable_helper.rb', line 26 def each (0...@size).each do |index| yield @objects[index] end end |