Skip to content

Instantly share code, notes, and snippets.

@stephenhowells
Last active December 21, 2015 03:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stephenhowells/6245701 to your computer and use it in GitHub Desktop.
Remove widows in your blog post headings by adding an " " between the last two words in the title if it is three words or more.
def no_widows(arg)
if arg.strip.count(" ") >= 2
arg.split[0...-1].join(" ") + " #{arg.split[-1]}"
else
arg
end
end
#Example usage:
title = "You Should Never Have Widows"
puts no_widows(title)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment