Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_extensions/string.rb

Overview

Extend class String with color codes

Instance Method Summary collapse

Instance Method Details

#color(type) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/core_extensions/string.rb', line 4

def color type
  return self unless $color
  color_code = case type
               when :bold             then 1
               when :white, :file     then 37
               when :error, :red      then 31
               when :green            then 32
               when :policy, :yellow  then 33
               end
  "\e[#{color_code}m#{self}\e[0m"
end