Class: Colorlib::ColoredCompound
- Inherits:
-
Object
- Object
- Colorlib::ColoredCompound
- Defined in:
- lib/colorlib/colored_compound.rb
Direct Known Subclasses
Constant Summary collapse
- @@makers =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #append(whatever) ⇒ Object (also: #<<)
-
#initialize ⇒ ColoredCompound
constructor
A new instance of ColoredCompound.
- #make(target) ⇒ Object
Constructor Details
#initialize ⇒ ColoredCompound
Returns a new instance of ColoredCompound.
6 7 8 |
# File 'lib/colorlib/colored_compound.rb', line 6 def initialize @strings = [] end |
Class Method Details
.register_maker(type, &block) ⇒ Object
29 30 31 |
# File 'lib/colorlib/colored_compound.rb', line 29 def self.register_maker(type, &block) @@makers[type] = block end |
Instance Method Details
#append(whatever) ⇒ Object Also known as: <<
10 11 12 13 |
# File 'lib/colorlib/colored_compound.rb', line 10 def append(whatever) @strings << whatever.is_a?(ColoredString) ? whatever : ColoredString.new(whatever.to_s) self # to return it end |
#make(target) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/colorlib/colored_compound.rb', line 17 def make(target) unless (maker = @@makers[target]) raise 'Invalid Target' end prev = ColorAttribute.new ret = '' @strings.each do |string| ret += maker.call string, prev end ret end |