diff options
author | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-06-29 22:39:55 -0300 |
---|---|---|
committer | Abinoam P. Marques Jr <abinoam@gmail.com> | 2017-06-29 22:39:55 -0300 |
commit | d6316303929cd822667eaa92e0a7fe21cfceb004 (patch) | |
tree | 49b4ce302a3c931579b0f23c2133a6c08d78cfb2 | |
parent | 2b5f0fafc67765506fb1fc4a6e6e107d7d83dcbc (diff) | |
download | highline-d6316303929cd822667eaa92e0a7fe21cfceb004.tar.gz |
Simplify HighLine.color with delegation
-rwxr-xr-x | lib/highline.rb | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/highline.rb b/lib/highline.rb index a79a294..5614980 100755 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -47,7 +47,7 @@ class HighLine extend SingleForwardable def_single_delegators :@default_instance, :agree, :ask, :choose, :say, :use_color=, :use_color?, :reset_use_color, - :track_eof=, :track_eof? + :track_eof=, :track_eof?, :color def self.default_instance @default_instance @@ -300,23 +300,20 @@ class HighLine # (:blue for BLUE, for example). A CLEAR will automatically be embedded to # the end of the returned String. # - # This method returns the original _string_ unchanged if HighLine::use_color? + # This method returns the original _string_ unchanged if use_color? # is +false+. # # @param string [String] string to be colored # @param colors [Array<Symbol>] array of colors like [:red, :blue] # @return [String] (ANSI escaped) colored string # @example - # HighLine.color("Sustainable", :green, :bold) + # cli = HighLine.new + # cli.color("Sustainable", :green, :bold) # # => "\e[32m\e[1mSustainable\e[0m" - def self.color( string, *colors ) - return string unless self.use_color? - Style(*colors).color(string) - end - - # (see .color) - # This method is a clone of the HighLine.color class method. - # But it checks for use_color? per instance + # + # # As class method (delegating to HighLine.default_instance) + # HighLine.color("Sustainable", :green, :bold) + # def color(string, *colors) return string unless use_color? HighLine.Style(*colors).color(string) |