module Colorize


With Colorize you can change the fore- and background colors and text decorations when rendering text on terminals supporting ANSI escape codes. It adds the colorize method to Object and thus all classes as its main interface, which calls to_s and surrounds it with the necessary escape codes when it comes to obtaining a string representation of the object.

Its first argument changes the foreground color:

require "colorize"

[1, 2, 3].colorize(:blue)

There are alternative ways to change the foreground color:


To change the background color, the following methods are available:


It's also possible to change the text decoration:


The colorize method returns a Colorize::Object instance, which allows chaining methods together:


With the toggle method you can temporarily disable adding the escape codes. Settings of the instance are preserved however and can be turned back on later:

# => "foo" without color
# => "foo" in red

Available colors are:


Available text decorations are:


Defined in: