Skip to content

Instantly share code, notes, and snippets.

@adammcarth
Created July 6, 2014 10:55
Show Gist options
  • Select an option

  • Save adammcarth/8aeab315336347e1b516 to your computer and use it in GitHub Desktop.

Select an option

Save adammcarth/8aeab315336347e1b516 to your computer and use it in GitHub Desktop.
<%
# 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