Sha256: acf19aa34ead1554d671be16cf6b9ef3379a01afbd23fb23c3a4c8ee6c47b71e

Contents?: true

Size: 720 Bytes

Versions: 14

Compression:

Stored size: 720 Bytes

Contents

module RubyExt::Observable
  def add_observer observer
    @observable_observers ||= []
    @observable_observers << observer unless @observable_observers.include? observer
  end

  def notify_observers method, *args
    raise "Invalid usage, method must be Symbol or String!" unless method.is_a?(Symbol) or method.is_a?(String)
    @observable_observers.each{|observer| observer.respond_to method, *args} if @observable_observers
  end

  def delete_observer observer
    @observable_observers.delete observer if @observable_observers
  end

  def delete_observers
    @observable_observers.clear if @observable_observers
  end

  def observers_count
    @observable_observers ? @observable_observers.size : 0
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ruby_ext-4.0.3 lib/ruby_ext/more/observable.rb
ruby_ext-4.0.2 lib/ruby_ext/more/observable.rb
ruby_ext-4.0.1 lib/ruby_ext/more/observable.rb
ruby_ext-4.0.0 lib/ruby_ext/more/observable.rb
ruby_ext-0.5.10 lib/ruby_ext/more/observable.rb
ruby_ext-0.5.9 lib/ruby_ext/more/observable.rb
ruby_ext-0.5.8 lib/ruby_ext/more/observable.rb
ruby_ext-0.5.7 lib/ruby_ext/more/observable.rb
ruby_ext-0.5.6 lib/ruby_ext/more/observable.rb
ruby_ext-0.5.5 lib/ruby_ext/more/observable.rb
ruby_ext-0.5.4 lib/ruby_ext/more/observable.rb
ruby_ext-0.5.3 lib/ruby_ext/more/observable.rb
ruby_ext-0.5.2 lib/ruby_ext/more/observable.rb
ruby_ext-0.5.1 lib/ruby_ext/more/observable.rb