Skip to content

Instantly share code, notes, and snippets.

@avescodes
Created August 12, 2009 15:09
Show Gist options
  • Save avescodes/166560 to your computer and use it in GitHub Desktop.
Save avescodes/166560 to your computer and use it in GitHub Desktop.
# Code Golf: Text Area Tag Edition
# Ladies and Gentlemen here is the function
# Smallest (and least legible) rewrite wins!
def size_for_text_area_tag(string, cols = 40)
lines = string.split("\n")
rows = lines.map(&:length).inject(0) do |sum,len|
sum + if len/cols > 0
len/cols
else
1
end
end
"#{cols}x#{rows+2}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment