Sha256: d0de75f250411f74796368f8b36672f956c28c809ed3e4cba6d895a919d741e3

Contents?: true

Size: 637 Bytes

Versions: 4

Compression:

Stored size: 637 Bytes

Contents

module React

  class Observable

    def initialize(value, on_change = nil, &block)
      @value = value
      @on_change = on_change || block
    end

    def method_missing(method_sym, *args, &block)
      @value.send(method_sym, *args, &block).tap { |result| @on_change.call @value }
    end

    def respond_to?(method, *args)
      if [:call, :to_proc].include? method
        true
      else
        @value.respond_to? method, *args
      end
    end

    def call(new_value)
      @on_change.call new_value
      @value = new_value
    end

    def to_proc
      lambda { |arg = @value| @on_change.call arg }
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
reactive-ruby-0.7.28 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.27 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.26 lib/reactive-ruby/observable.rb
reactive-ruby-0.7.25 lib/reactive-ruby/observable.rb