Class: String

Inherits:
Object show all
Defined in:
lib/core_ext/string/color.rb,
lib/core_ext/string/indent.rb,
lib/core_ext/string/unindent.rb

Instance Method Summary collapse

Instance Method Details

#colorize(color_code) ⇒ Object

colorization



3
4
5
# File 'lib/core_ext/string/color.rb', line 3

def colorize(color_code)
  "\e[#{color_code}m#{self}\e[0m"
end

#greenObject



11
12
13
# File 'lib/core_ext/string/color.rb', line 11

def green
  colorize(32)
end

#indent(level) ⇒ Object



2
3
4
# File 'lib/core_ext/string/indent.rb', line 2

def indent(level)
  split("\n").map { |line| ' ' * (level * 2) + line }.join("\n")
end

#pinkObject



19
20
21
# File 'lib/core_ext/string/color.rb', line 19

def pink
  colorize(35)
end

#redObject



7
8
9
# File 'lib/core_ext/string/color.rb', line 7

def red
  colorize(31)
end

#unindentObject



2
3
4
# File 'lib/core_ext/string/unindent.rb', line 2

def unindent
  gsub /^#{self[/\A\s*/]}/, ''
end

#yellowObject



15
16
17
# File 'lib/core_ext/string/color.rb', line 15

def yellow
  colorize(33)
end