Sha256: 7db456bf16c6de32e6cd6e99f0b18c067f9f98c248232323f6bc95ff092aebe1

Contents?: true

Size: 573 Bytes

Versions: 8

Compression:

Stored size: 573 Bytes

Contents

# The only trick in this array is that it's transpose is memoized until
# it is tainted.  This will reduce computations elegantly. 
class TransposableArray < CallbackArray

  after_taint :clear_cache
  
  orig_transpose = instance_method(:transpose)
  define_method(:transpose) {
    @transpose ||= orig_transpose.bind(self).call
  }
  
  # For debugging and testing purposes, it just feels dirty to always ask
  # for @ta.send(:instance_variable_get, :@transpose) 
  def cache
    @transpose
  end

  def clear_cache
    @transpose = nil
  end
  protected :clear_cache
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
davidrichards-data_frame-0.0.10 lib/data_frame/transposable_array.rb
davidrichards-data_frame-0.0.11 lib/data_frame/transposable_array.rb
davidrichards-data_frame-0.0.12 lib/data_frame/transposable_array.rb
davidrichards-data_frame-0.0.13 lib/data_frame/transposable_array.rb
davidrichards-data_frame-0.0.3 lib/data_frame/transposable_array.rb
davidrichards-data_frame-0.0.7 lib/data_frame/transposable_array.rb
davidrichards-data_frame-0.0.8 lib/data_frame/transposable_array.rb
davidrichards-data_frame-0.0.9 lib/data_frame/transposable_array.rb