# File lib/highline/string_extensions.rb, line 32 32: def self.included(base) 33: HighLine::COLORS.each do |color| 34: base.class_eval if public_instance_methods.map { |m| m.to_s }. include? "#{color.downcase}" undef :#{color.downcase} end def #{color.downcase} color(:#{color.downcase}) end 35: base.class_eval if public_instance_methods.map { |m| m.to_s }. include? "on_#{color.downcase}" undef :on_#{color.downcase} end def on_#{color.downcase} on(:#{color.downcase}) end 36: HighLine::STYLES.each do |style| 37: base.class_eval if public_instance_methods.map { |m| m.to_s }. include? "#{style.downcase}" undef :#{style.downcase} end def #{style.downcase} color(:#{style.downcase}) end 38: end 39: end 40: 41: base.class_eval do 42: if public_instance_methods.map { |m| m.to_s }.include? "color" 43: undef :color 44: end 45: if public_instance_methods.map { |m| m.to_s }.include? "foreground" 46: undef :foreground 47: end 48: def color(*args) 49: self.class.new(HighLine.color(self, *args)) 50: end 51: alias_method :foreground, :color 52: 53: if public_instance_methods.map { |m| m.to_s }.include? "on" 54: undef :on 55: end 56: def on(arg) 57: color(('on_' + arg.to_s).to_sym) 58: end 59: 60: if public_instance_methods.map { |m| m.to_s }.include? "uncolor" 61: undef :uncolor 62: end 63: def uncolor 64: self.class.new(HighLine.uncolor(self)) 65: end 66: 67: if public_instance_methods.map { |m| m.to_s }.include? "rgb" 68: undef :rgb 69: end 70: def rgb(*colors) 71: color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join 72: raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/ 73: color("rgb_#{color_code}".to_sym) 74: end 75: 76: if public_instance_methods.map { |m| m.to_s }.include? "on_rgb" 77: undef :on_rgb 78: end 79: def on_rgb(*colors) 80: color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join 81: raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/ 82: color("on_rgb_#{color_code}".to_sym) 83: end 84: 85: if public_instance_methods.map { |m| m.to_s }.include? "method_missing" 86: undef :method_missing 87: end 88: # TODO Chain existing method_missing 89: def method_missing(method, *args, &blk) 90: if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/ 91: color(method) 92: else 93: raise NoMethodError, "undefined method `#{method}' for #<#{self.class}:#{'%#x'%self.object_id}>" 94: end 95: end 96: end 97: end
# File lib/highline/string_extensions.rb, line 72 72: def color(*args) 73: self.class.new(HighLine.color(self, *args)) 74: end
TODO Chain existing method_missing
# File lib/highline/string_extensions.rb, line 113 113: def method_missing(method, *args, &blk) 114: if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/ 115: color(method) 116: else 117: raise NoMethodError, "undefined method `#{method}' for #<#{self.class}:#{'%#x'%self.object_id}>" 118: end 119: end
# File lib/highline/string_extensions.rb, line 80 80: def on(arg) 81: color(('on_' + arg.to_s).to_sym) 82: end
# File lib/highline/string_extensions.rb, line 103 103: def on_rgb(*colors) 104: color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join 105: raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/ 106: color("on_rgb_#{color_code}".to_sym) 107: end
# File lib/highline/string_extensions.rb, line 94 94: def rgb(*colors) 95: color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join 96: raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/ 97: color("rgb_#{color_code}".to_sym) 98: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.