rubymotion-community / BubbleWrap

Cocoa wrappers and helpers for RubyMotion (Ruby for iOS and OS X) - Making Cocoa APIs more Ruby like, one API at a time. Fork away and send your pull requests
Other
1.18k stars 208 forks source link

Allow passing multiple key paths to #observe #390

Closed dv closed 9 years ago

dv commented 10 years ago

This PR adds the ability to observe multiple keypaths with the same call/block:

observe @obj, [:name, :age, :location] do
  update_description
end

This will call that block if either one of the three keypaths change.

Right now this is implemented using a trivial loop over the original #observe call so the block is only passed old_value and new_value, but maybe we should change the structure so that it passes the keypath that changed into the block as well, so we could do this:

observe @obj, [:name, :age, :location] do |old_value, new_value, key_path|
  puts "#{key_path} changed from #{old_value} to #{new_value}"
end
clayallsopp commented 10 years ago

Sweet! I think the key_path argument would be necessary for many cases - can you add that optionality w/ specs? Then will merge

dv commented 10 years ago

Will do!

markrickert commented 9 years ago

Implemented in #460