Last active
December 21, 2015 03:58
-
-
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.
This file contains hidden or 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