Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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']
@i0rek

This comment has been minimized.

Copy link
Owner Author

@i0rek i0rek commented Oct 1, 2010

This script formats a method call from

do_something_very_fancy(with_a_lot_and, very_long_parameters, so_it_exceeds_78_character_length)

to

do_something_very_fancy(
    with_a_lot_and,
    very_long_parameters,
    so_it_exceeds_78_character_length
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment