How to add methods to existing classes

A quick and easy tip today. It won’t impress the veteran ruby developer, but it will impress every ruby newcomers, guaranteed!

Say I have a horse racing ruby application that allow people to know information about every competing horses. I have an input box that people can use to enter the name of a horse. Once they click OK, information about the specified horse is displayed to the user.

Instead of going the traditonal route, how about adding a “horse” method to the String class? It could not be easier :

Talk about some great syntactic ruby sugar!