use regular expressions
line = "A horse! this is a horse!" puts line[/horse!$/] # The regular expression /horse!$/ asks, "Does the word horse, followed by ! come at the end of the line ($)?" # If this is true, this call returns horse!; nil if not.