Sha256: 25c26eaebbf218fb735949201016cd8c1d6ab1e6fd72d3e98a651c004f07b98f
Contents?: true
Size: 1.54 KB
Versions: 2
Compression:
Stored size: 1.54 KB
Contents
class Tailor module CompositeObservable def self.define_observer(name) define_method("add_#{name}_observer") do |observer| @notifiers = {} unless defined? @notifiers @notifiers[name] = {} unless @notifiers[name] call_back = "#{name}_update".to_sym unless observer.respond_to? call_back raise NoMethodError, "observer does not respond to '#{call_back}'" end @notifiers[name][observer] = call_back end define_method("notify_#{name}_observers") do |*args| if defined? @notifier_state and @notifier_state if @notifier_state[name] if defined? @notifiers and @notifiers[name] @notifiers[name].each do |k, v| k.send(v, *args) end end end end end define_method("#{name}_changed") do @notifier_state = {} unless defined? @notifier_state @notifier_state[name] = true end end define_observer :comma define_observer :comment define_observer :const define_observer :embexpr_beg define_observer :embexpr_end define_observer :file define_observer :ident define_observer :ignored_nl define_observer :kw define_observer :lbrace define_observer :lbracket define_observer :lparen define_observer :nl define_observer :period define_observer :rbrace define_observer :rbracket define_observer :rparen define_observer :sp define_observer :tstring_beg define_observer :tstring_end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tailor-1.0.0.alpha2 | lib/tailor/composite_observable.rb |
tailor-1.0.0.alpha | lib/tailor/composite_observable.rb |