Sha256: 140c1f775f79507b65390fb0a2a26ba3c4bfc0b4acaaa5d8f333685d1f608620
Contents?: true
Size: 1 KB
Versions: 3
Compression:
Stored size: 1 KB
Contents
module ObservableAttributes def has_attributes(*names) if names.first.is_a? Hash names.first.each do |name, default| has_attribute name, default end else names.each do |name| has_attribute name end end end def has_attribute(name, value=nil) @evented_attributes ||= [] unless has_attribute? name @evented_attributes << name self.metaclass.send :kvo_attr_accessor, name self.define_singleton_method "#{name}?" do self.send name end self.send("#{name}=", value) end end def has_attribute?(name) @evented_attributes && @evented_attributes.include?(name) end def attributes {}.tap do |atts| if @evented_attributes @evented_attributes.each do |name| atts[name] = self.send name end end end end def self.included(klass) klass.instance_eval do include Kvo def has_attribute(name) kvo_attr_accessor name end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
gamebox-0.4.0.rc5 | lib/gamebox/lib/observable_attributes.rb |
gamebox-0.4.0.rc4 | lib/gamebox/lib/observable_attributes.rb |
gamebox-0.4.0.rc3 | lib/gamebox/lib/observable_attributes.rb |