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

Add support for Object#method to the Eventable module #359

Closed MarkVillacampa closed 10 years ago

MarkVillacampa commented 10 years ago

Hello! I make heavy use of the Eventable module, and sometimes I find it useful to re-use some methods as events. It looks similar to this:

object.on :my_event, &method(:my_method)

However, Method#to_proc returns a different object each time, and this makes it difficult to unbind the event when the VC gets deallocated. This is easily solved by passing a simple Method object

object.on :my_event, method(:my_method)

My implementation is backwards compatible with the existing one so it shouldn't cause any problem to existing apps.

Also, be aware that the current test suite fails, as Object#method leaks. This bug has been reported and will be fixed in the next RM release (http://hipbyte.myjetbrains.com/youtrack/issue/RM-456).

clayallsopp commented 10 years ago

Wow, Object#method leaking is very unexpected, good thing the test detects it.

Thanks!

MarkVillacampa commented 10 years ago

Just a heads up, RM 2.25 fixes the Object#method leak so the specs should be passing now.

clayallsopp commented 10 years ago

Thanks for the heads up, it is! https://travis-ci.org/rubymotion/BubbleWrap/builds/22304051