Class: String

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

Constant Summary collapse

COLOR =
{
  red: 31,
  blue: 34,
  green: 32,
  black: 37,
  purple: 35,
  yellow: 33,
  orange: 33
}.freeze

Instance Method Summary collapse

Instance Method Details

#colorize(*code) ⇒ Object



12
13
14
# File 'lib/core_ext.rb', line 12

def colorize(*code)
  "\e[#{code.join(";")}m#{self}\e[0m"
end

#labelize(*code) ⇒ Object



16
17
18
# File 'lib/core_ext.rb', line 16

def labelize(*code)
  colorize(93)
end

#paint(color) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/core_ext.rb', line 26

def paint(color)
  if respond_to?(color.to_sym)
    public_send(color)
  else
    self
  end
end

#shortObject



34
35
36
37
38
39
40
# File 'lib/core_ext.rb', line 34

def short
  if self.size > 50
    self.truncate(50) + "..."
  else
    self
  end
end