module RuGUI::PropertyChangedSupport::ClassMethods
Public Instance Methods
when_property_changed(property, method_or_options = {}, &block)
click to toggle source
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>
# 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