Created
October 19, 2010 04:28
-
-
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)
This file contains hidden or 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
# 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