Class: String

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

Overview

monkey patch in some color effects string methods

Instance Method Summary collapse

Instance Method Details

#camel_caseObject



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

def camel_case
  return self if self !~ /_/ && self =~ /[A-Z]+.*/
  split('_').map(&:capitalize).join
end

#cyanObject



6
# File 'lib/retrospec.rb', line 6

def cyan;           "\033[36m#{self}\033[0m" end

#fatalObject



9
# File 'lib/retrospec.rb', line 9

def fatal;          red                      end

#greenObject



5
# File 'lib/retrospec.rb', line 5

def green;          "\033[32m#{self}\033[0m" end

#infoObject



10
# File 'lib/retrospec.rb', line 10

def info;           green                    end

#redObject



4
# File 'lib/retrospec.rb', line 4

def red;            "\033[31m#{self}\033[0m" end

#underscoreObject



17
18
19
20
21
22
23
# File 'lib/retrospec.rb', line 17

def underscore
  self.gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
end

#warningObject



8
# File 'lib/retrospec.rb', line 8

def warning;        yellow                   end

#yellowObject



7
# File 'lib/retrospec.rb', line 7

def yellow;         "\033[33m#{self}\033[0m" end