Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryecroft/3055835 to your computer and use it in GitHub Desktop.
Save ryecroft/3055835 to your computer and use it in GitHub Desktop.
Ruby script to translate Objective-C method calls into MacRuby
#!/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