Sha256: c9d3b83ec213e6aa4e9d05b8608e72c9e74ee44d5ddbede59cc1a852e751c57f
Contents?: true
Size: 1.11 KB
Versions: 10
Compression:
Stored size: 1.11 KB
Contents
module ReactiveAccessors module ClassMethods # Create a method to read a reactive value from an instance value. If it # is not setup, create it so it can be updated through the reactive value # at a later point. def reactive_reader(*names) names.each do |name| var_name = :"@#{name}" define_method(name.to_sym) do value = instance_variable_get(var_name) unless value value = ReactiveValue.new(nil) instance_variable_set(var_name, value) end value end end end def reactive_writer(*names) names.each do |name| var_name = :"@#{name}" define_method(:"#{name}=") do |new_value| value = instance_variable_get(var_name) if value value.cur = new_value else instance_variable_set(var_name, ReactiveValue.new(value)) end end end end def reactive_accessor(*names) reactive_reader(*names) reactive_writer(*names) end end def self.included(base) base.send :extend, ClassMethods end end
Version data entries
10 entries across 10 versions & 1 rubygems