Forked from ryecroft/Objective-C to MacRuby method translate
Created
November 28, 2012 00:19
-
-
Save zhaocai/4158133 to your computer and use it in GitHub Desktop.
Ruby script to translate Objective-C method calls into 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
#!/usr/bin/env ruby | |
# Translates an objective C method call on the pasteboard, | |
# as copied from the docs, into MacRuby syntax, placing it | |
# back on the pasteboard. | |
# @example | |
# '+ (NSColor *)colorWithCalibratedRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha' | |
# => 'colorWithCalibratedRed(red, green:green, blue:blue, alpha:alpha)' | |
string = `pbpaste` | |
string.sub!(/^[-+]*\s*(\([^)]+\))/, "") | |
string.sub!(/(^[^:]+):/, '\1__placeholder__') | |
string.gsub!(/(\([^)]+?\))/, "") | |
string.gsub!(/\s/, ', ') | |
string.gsub!(/__placeholder__/, '(') | |
string.gsub!(/$/, ')') | |
`echo '#{string}' | pbcopy` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment