32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# 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}\n def \#{color}\n color(:\#{color})\n end\n END\n\n base.class_eval <<-END\n undef :on_\#{color} if method_defined? :on_\#{color}\n def on_\#{color}\n on(:\#{color})\n end\n END\n HighLine::STYLES.each do |style|\n style = style.downcase\n base.class_eval <<-END\n undef :\#{style} if method_defined? :\#{style}\n def \#{style}\n color(:\#{style})\n end\n END\n end\n end\n\n base.class_eval do\n undef :color if method_defined? :color\n undef :foreground if method_defined? :foreground\n def color(*args)\n self.class.new(HighLine.color(self, *args))\n end\n alias_method :foreground, :color\n\n undef :on if method_defined? :on\n def on(arg)\n color(('on_' + arg.to_s).to_sym)\n end\n\n undef :uncolor if method_defined? :uncolor\n def uncolor\n self.class.new(HighLine.uncolor(self))\n end\n\n undef :rgb if method_defined? :rgb\n def rgb(*colors)\n color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join\n raise \"Bad RGB color \#{colors.inspect}\" unless color_code =~ /^[a-fA-F0-9]{6}/\n color(\"rgb_\#{color_code}\".to_sym)\n end\n\n undef :on_rgb if method_defined? :on_rgb\n def on_rgb(*colors)\n color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join\n raise \"Bad RGB color \#{colors.inspect}\" unless color_code =~ /^[a-fA-F0-9]{6}/\n color(\"on_rgb_\#{color_code}\".to_sym)\n end\n\n # TODO Chain existing method_missing\n undef :method_missing if method_defined? :method_missing\n def method_missing(method, *args, &blk)\n if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/\n color(method)\n else\n raise NoMethodError, \"undefined method `\#{method}' for #<\#{self.class}:\#{'%#x'%self.object_id}>\"\n end\n end\n end\nend\n"
|