Module: Colorize::InstanceMethods

### Home Classes Methods

### In Files

- lib/colorize/instance_methods.rb

### Methods

- #colorize
- #colorized?
- #uncolorize

### Class/Module Index

Quicksearch

- Colorize
- Colorize::ClassMethods
- Colorize::InstanceMethods
- String

No matching classes.

# Colorize::InstanceMethods

### Public Instance Methods

colorize(params) click to toggle source

Change color of string

Examples:

    puts "This is blue".colorize(:blue)
    puts "This is light blue".colorize(:light_blue)
    puts "This is also blue".colorize(:color => :blue)
    puts "This is light blue with red background".colorize(:color => :light_blue, :background => :red)
    puts "This is light blue with red background".colorize(:light_blue ).colorize( :background => :red)
    puts "This is blue text on red".blue.on_red
    puts "This is red on blue".colorize(:red).on_blue
    puts "This is red on blue and underline".colorize(:red).on_blue.underline
    puts "This is blue text on red".blue.on_red.blink
    puts "This is uncolorized".blue.on_red.uncolorize

    # File lib/colorize/instance_methods.rb, line 20
    def colorize(params)
      return self if self.class.disable_colorization
      require_windows_libs
      scan_for_colors.inject('') do |str, match|
        defaults_colors(match)
        colors_from_params(match, params)
        str << "\0033[#{match[0]};#{match[1]};#{match[2]}m#{match[3]}\0033[0m"
      end
    end

colorized?() click to toggle source

Return true if string is colorized

    # File lib/colorize/instance_methods.rb, line 42
    def colorized?
      scan_for_colors.reject(&:last).any?
    end

uncolorize() click to toggle source

Return uncolorized string

    # File lib/colorize/instance_methods.rb, line 33
    def uncolorize
      scan_for_colors.inject('') do |str, match|
        str << (match[3] || match[4])
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.