### Home Classes Methods

### In Files

- lib/highline/string_extensions.rb

### Methods

- ::included
- #color
- #method_missing
- #on
- #on_rgb
- #rgb
- #uncolor

### Files

- CHANGELOG
- INSTALL
- LICENSE
- README.rdoc
- TODO

### Class/Module Index

Quicksearch

- HighLine
- HighLine::ColorScheme
- HighLine::HighLine
- HighLine::HighLine::HighLine
- HighLine::HighLine::HighLine::String
- HighLine::Menu
- HighLine::Question
- HighLine::Question::NoAutoCompleteMatch
- HighLine::QuestionError
- HighLine::SampleColorScheme
- HighLine::Simulate
- HighLine::StringExtensions
- HighLine::Style
- HighLine::SystemExtensions
- HighLine::SystemExtensions::WinAPI
- IO
- Kernel
- Object
- String
- StringIO

No matching classes.

# HighLine::StringExtensions

### Public Class Methods

included(base) click to toggle source

    # File lib/highline/string_extensions.rb, line 32
    def self.included(base)
      HighLine::COLORS.each do |color|
        color = color.downcase
        base.class_eval           undef :#{color} if method_defined? :#{color}          def #{color}            color(:#{color})          end

        base.class_eval           undef :on_#{color} if method_defined? :on_#{color}          def on_#{color}            on(:#{color})          end
        HighLine::STYLES.each do |style|
          style = style.downcase
          base.class_eval             undef :#{style} if method_defined? :#{style}            def #{style}              color(:#{style})            end
        end
      end

      base.class_eval do
        undef :color if method_defined? :color
        undef :foreground if method_defined? :foreground
        def color(*args)
          self.class.new(HighLine.color(self, *args))
        end
        alias_method :foreground, :color

        undef :on if method_defined? :on
        def on(arg)
          color(('on_' + arg.to_s).to_sym)
        end

        undef :uncolor if method_defined? :uncolor
        def uncolor
          self.class.new(HighLine.uncolor(self))
        end

        undef :rgb if method_defined? :rgb
        def rgb(*colors)
          color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
          raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
          color("rgb_#{color_code}".to_sym)
        end

        undef :on_rgb if method_defined? :on_rgb
        def on_rgb(*colors)
          color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
          raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
          color("on_rgb_#{color_code}".to_sym)
        end

        # TODO Chain existing method_missing
        undef :method_missing if method_defined? :method_missing
        def method_missing(method, *args, &blk)
          if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/
            color(method)
          else
            raise NoMethodError, "undefined method `#{method}' for #<#{self.class}:#{'%#x'%self.object_id}>"
          end
        end
      end
    end

### Public Instance Methods

color(*args) click to toggle source

    # File lib/highline/string_extensions.rb, line 62
    def color(*args)
      self.class.new(HighLine.color(self, *args))
    end

method_missing(method, *args, &blk) click to toggle source

    # File lib/highline/string_extensions.rb, line 93
    def method_missing(method, *args, &blk)
      if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/
        color(method)
      else
        raise NoMethodError, "undefined method `#{method}' for #<#{self.class}:#{'%#x'%self.object_id}>"
      end
    end

on(arg) click to toggle source

    # File lib/highline/string_extensions.rb, line 68
    def on(arg)
      color(('on_' + arg.to_s).to_sym)
    end

on_rgb(*colors) click to toggle source

    # File lib/highline/string_extensions.rb, line 85
    def on_rgb(*colors)
      color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
      raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
      color("on_rgb_#{color_code}".to_sym)
    end

rgb(*colors) click to toggle source

    # File lib/highline/string_extensions.rb, line 78
    def rgb(*colors)
      color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
      raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
      color("rgb_#{color_code}".to_sym)
    end

uncolor() click to toggle source

    # File lib/highline/string_extensions.rb, line 73
    def uncolor
      self.class.new(HighLine.uncolor(self))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.