Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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