Created
October 1, 2010 04:55
-
-
Save hanshasselberg/605761 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
def format_method text, line | |
line.match /^(\s*)/ | |
spaces = $1 | |
text.match /^(\s*)([\w\d\s\_]+)\s*\((.*)\)/ | |
formatted = "#{$2}(\n#{spaces}\t" | |
formatted += $3. | |
gsub(" ", ""). | |
gsub(",", ",\n#{spaces}\t"). | |
gsub('=>', ' => '). | |
gsub('{', '{ '). | |
gsub('}', ' }'). | |
gsub('[', '[ ').gsub(']', ' ]') | |
formatted += "\n#{spaces})" | |
formatted | |
end | |
def main selected_text, line | |
if selected_text.match /^[\w\d\_]+\((.*)\)$/ | |
puts format_method(selected_text, line) | |
else | |
puts selected_text | |
end | |
end | |
# main 'do( a, b, c )', ' do( a, b, c )' | |
main ENV['TM_SELECTED_TEXT'], ENV['TM_CURRENT_LINE'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script formats a method call from
to