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.
This file contains 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
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