Skip to content

Instantly share code, notes, and snippets.

@Lockyy
Last active June 6, 2023 16:21
Show Gist options
  • Save Lockyy/1357ea7f307f1fecc4da1c3a97a1151d to your computer and use it in GitHub Desktop.
Save Lockyy/1357ea7f307f1fecc4da1c3a97a1151d to your computer and use it in GitHub Desktop.
Monkey patch to add `.red`/`.green`/`.yellow` to the String class to color strings on console output
class String
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red
colorize(31)
end
def green
colorize(32)
end
def yellow
colorize(33)
end
end
@Lockyy
Copy link
Author

Lockyy commented Oct 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment