Skip to content

Instantly share code, notes, and snippets.

@chrislloyd
Created February 23, 2011 13:51
Show Gist options
  • Save chrislloyd/840449 to your computer and use it in GitHub Desktop.
Save chrislloyd/840449 to your computer and use it in GitHub Desktop.
A few handy snippets when working with MacRuby.
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