Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/blackjack/strings/string.rb
Overview
Class that modifies the String class and equips it with a method to set terminal properties of a string
Instance Method Summary collapse
-
#set_attributes(attributes, previous_attributes = []) ⇒ string
Sets the terminal attributes of the string.
Instance Method Details
#set_attributes(attributes, previous_attributes = []) ⇒ string
Sets the terminal attributes of the string
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/blackjack/strings/string.rb', line 30 def set_attributes(attributes, previous_attributes = []) mode_start_string = '' modes_end_string = "\e[0m" attributes.each { |attribute| mode_start_string += "\e[#{attribute}m" } attributed_string = mode_start_string attributed_string += self.gsub("\n", "#{modes_end_string}\n#{mode_start_string}") attributed_string += modes_end_string previous_attributes.each { |attribute| attributed_string += "\e[#{attribute}m" } attributed_string end |