Class: Pastel::Delegator Private
- Inherits:
-
Object
- Object
- Pastel::Delegator
- Extended by:
- Forwardable
- Defined in:
- lib/pastel/delegator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Wrapes the DecoratorChain to allow for easy resolution of string coloring.
Class Method Summary collapse
-
.wrap(resolver, chain = DecoratorChain.empty) ⇒ Object
Wrap resolver and chain.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare delegated objects for equivalence of attributes.
-
#eql?(other) ⇒ Boolean
Compare delegated objects for equality of attributes.
-
#hash ⇒ Numeric
Hash for this instance and its attributes.
-
#initialize(resolver, chain) ⇒ Delegator
constructor
private
Create Delegator.
-
#inspect ⇒ String
(also: #to_s)
Object string representation.
Constructor Details
#initialize(resolver, chain) ⇒ Delegator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create Delegator
Used internally by Pastel
38 39 40 41 |
# File 'lib/pastel/delegator.rb', line 38 def initialize(resolver, chain) @resolver = resolver @chain = chain end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object (protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Handles color method calls
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pastel/delegator.rb', line 89 def method_missing(method_name, *args, &block) new_chain = chain.add(method_name) delegator = self.class.wrap(resolver, new_chain) if args.empty? && method_name.to_sym != :detach delegator else strings = args.dup strings << evaluate_block(&block) if block_given? resolver.resolve(new_chain, strings.join) end end |
Class Method Details
.wrap(resolver, chain = DecoratorChain.empty) ⇒ Object
Wrap resolver and chain
25 26 27 |
# File 'lib/pastel/delegator.rb', line 25 def self.wrap(resolver, chain = DecoratorChain.empty) new(resolver, chain) end |
Instance Method Details
#==(other) ⇒ Boolean
Compare delegated objects for equivalence of attributes
57 58 59 |
# File 'lib/pastel/delegator.rb', line 57 def ==(other) other.is_a?(self.class) && chain == other.chain end |
#eql?(other) ⇒ Boolean
Compare delegated objects for equality of attributes
48 49 50 |
# File 'lib/pastel/delegator.rb', line 48 def eql?(other) instance_of?(other.class) && chain.eql?(other.chain) end |
#hash ⇒ Numeric
Hash for this instance and its attributes
76 77 78 |
# File 'lib/pastel/delegator.rb', line 76 def hash [self.class, chain].hash end |
#inspect ⇒ String Also known as: to_s
Object string representation
66 67 68 |
# File 'lib/pastel/delegator.rb', line 66 def inspect "#<Pastel styles=#{chain.map(&:to_s)}>" end |