Skip to content

Instantly share code, notes, and snippets.

@ggilder
Created October 19, 2010 04:28
Show Gist options
  • Save ggilder/633608 to your computer and use it in GitHub Desktop.
Save ggilder/633608 to your computer and use it in GitHub Desktop.
Restore an Objective-C method signature from MacRuby's automatic Ruby-style conversion (such as that passed to method_missing)
# Takes an Objective-C method signature, automatically converted to "Ruby-style" by MacRuby, and restores it.
# Restored method and arguments are returned in an array.
def restoreObjcMethodSignature(method, args)
if ((args.length == 2) && (args[1].is_a? Hash))
method = method+':'+args[1].keys.join(':')
args = [args[0], *args[1].values]
end
[method, args]
end
# Example usage
def method_missing(method, *args)
newMethod, newArgs = restoreObjcMethodSignature(method, args)
if @cocoaObject.respond_to?(newMethod)
@cocoaObject.send(newMethod, *newArgs)
else
super
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment