Sha256: c584db9338e4db28b25f237166e4b6e7dd27e8d0fedad1b1e6681267e80fd9da

Contents?: true

Size: 592 Bytes

Versions: 3

Compression:

Stored size: 592 Bytes

Contents

# The only trick in this array is that it's transpose is memoized until
# it is tainted.  This should 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

3 entries across 3 versions & 2 rubygems

Version Path
davidrichards-data_frame-0.0.19 lib/data_frame/transposable_array.rb
davidrichards-data_frame-0.0.20 lib/data_frame/transposable_array.rb
data_frame-0.1.8 lib/data_frame/transposable_array.rb