Created
February 23, 2011 13:51
-
-
Save chrislloyd/840449 to your computer and use it in GitHub Desktop.
A few handy snippets when working with MacRuby.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Symbol | |
def to_selector | |
"#{self}:".to_sym | |
end | |
end | |
class NSObject | |
# Usage: | |
# bind 'Rollin', :start_server, from: obj | |
def bind name, method, opts={} | |
NSNotificationCenter.defaultCenter.addObserver self, | |
selector: method.to_selector, | |
name: name, | |
object: opts[:from] | |
end | |
# Usage: | |
# trigger 'Rollin' | |
def trigger name, object=nil | |
NSNotificationCenter.defaultCenter.postNotificationName name, | |
object: object || self | |
end | |
# Defers the method to be called until the next event pass | |
def defer method, arg=nil | |
performSelector method.to_selector, withObject:arg, afterDelay:0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment