Created
July 6, 2014 10:55
-
-
Save adammcarth/8aeab315336347e1b516 to your computer and use it in GitHub Desktop.
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
| <% | |
| # Function to shorten a string | |
| def truncate(string, characters) | |
| if characters < string.length | |
| truncated = string.slice(0, characters) | |
| return truncated + "..." | |
| else | |
| return string | |
| end | |
| end | |
| truncate("The best is yet to come.", 11) | |
| #=> The best is... | |
| truncate("The best is yet to come.", 50) | |
| #=> The best is yet to come. | |
| %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment