class ReactiveArray

A wrapper around an array that calls react! on any ‘send’. This enables you to react to certain events or changes to the array.

Constants

OPERATORS

Public Class Methods

new(*args) { |self| ... } click to toggle source
# File lib/reactive_array.rb, line 4
def initialize(*args)
  @array = Array.new(*args)
  yield self if block_given?
end

Public Instance Methods

method_missing(m, *args, &block) click to toggle source
# File lib/reactive_array.rb, line 29
def method_missing(m, *args, &block)
  x = @array.send(m, *args, &block)
  react!(m)
  # if the @array returned self, we return self too (but we will refer to our wrapper class of course)
  x.equal?(@array) ? self : x
end
react!(m) click to toggle source
# File lib/reactive_array.rb, line 36
def react!(m)
  raise NotImplemented, "responsibility of subclass"
  # puts "reacting on #{m.inspect}"
end
to_a() click to toggle source
# File lib/reactive_array.rb, line 14
def to_a
  react!(:to_a)
  @array
end
Also aliased as: to_ary
to_ary()
Alias for: to_a
to_s() click to toggle source
# File lib/reactive_array.rb, line 9
def to_s
  react!(:to_s)
  @array.to_s
end