Sha256: 6a5ad3774e34bf97ec84daeeb2f3ebe7df7b48c0b6382814da5b7d87009f7752

Contents?: true

Size: 590 Bytes

Versions: 4

Compression:

Stored size: 590 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) {
    self.untaint
    @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

4 entries across 4 versions & 1 rubygems

Version Path
davidrichards-data_frame-0.0.14 lib/data_frame/transposable_array.rb
davidrichards-data_frame-0.0.15 lib/data_frame/transposable_array.rb
davidrichards-data_frame-0.0.17 lib/data_frame/transposable_array.rb
davidrichards-data_frame-0.0.18 lib/data_frame/transposable_array.rb