Class: String

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

Overview

add colors to String class

Instance Method Summary collapse

Instance Method Details

#blueObject



18
# File 'lib/listing.rb', line 18

def blue; self.colorize(34);end

#colorize(code) ⇒ Object



7
8
9
10
11
# File 'lib/listing.rb', line 7

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

#cyanObject



20
# File 'lib/listing.rb', line 20

def cyan; self.colorize(36);end

#greenObject



16
# File 'lib/listing.rb', line 16

def green; self.colorize(32);end

#purpleObject



19
# File 'lib/listing.rb', line 19

def purple; self.colorize(35);end

#redObject

I tried to put “define_method” in a loop but it was having none of it Please accept my humble apologies



15
# File 'lib/listing.rb', line 15

def red; self.colorize(31);end

#yellowObject



17
# File 'lib/listing.rb', line 17

def yellow; self.colorize(33);end