Module: RuGUI::PropertyChangedSupport::ClassMethods

Defined in:
lib/rugui/property_changed_support.rb

Instance Method Summary collapse

Instance Method Details

#when_property_changed(property, method_or_options = {}, &block) ⇒ Object

Invoked when a property was changed.

Example: <tt> when_property_changed :name do |observable, new_value, old_value|

puts "Hey! The property 'name' of the #{observable.class.name} was changed from #{old_value} to #{new_value}."

end </tt>

Or you can inform the observable: <tt> when_property_changed :name, :observable => :rabbit do |observable, new_value, old_value|

puts "Hey! The property 'name' of the 'rabbit' was changed from #{old_value} to #{new_value}."

end </tt>

If you can inform a method to be called: <tt> when_property_changed :name, :puts_anything

def puts_anything(observable, new_value, old_value)

puts "Hey! The property 'name' of the #{observable.class.name} was changed from #{old_value} to #{new_value}."

end </tt>

Or you can inform the observable and a method to be called. <tt> when_property_changed :name, :observable => :rabbit, :call => :puts_anything

def puts_anything(observable, new_value, old_value)

puts "Hey! The property 'name' of the 'rabbit' was changed from #{old_value} to #{new_value}."

end </tt> </tt>



39
40
41
42
43
44
45
# File 'lib/rugui/property_changed_support.rb', line 39

def when_property_changed(property, method_or_options = {}, &block)
  property_changed_block = RuGUI::PropertyChangedSupport::PropertyChangedBlock.new
  property_changed_block.property = property
  property_changed_block.set_options(method_or_options)
  property_changed_block.block = block if block_given?
  self.property_changed_blocks << property_changed_block
end