class Pastel::Detached

A class representing detached color

Attributes

styles[R]

@api private

Public Class Methods

new(color, *styles) click to toggle source

Initialize a detached object

@param [Pastel::Color] color

the color instance

@param [Array] styles

the styles to be applied

@api private

# File lib/pastel/detached.rb, line 14
def initialize(color, *styles)
  @color  = color
  @styles = styles.dup
  freeze
end

Public Instance Methods

==(other) click to toggle source

Compare detached objects for equivalence of attributes

@return [Boolean]

@api public

# File lib/pastel/detached.rb, line 57
def ==(other)
  other.is_a?(self.class) && styles == other.styles
end
[](*args)
Alias for: call
call(*args) click to toggle source

Decorate the values corresponding to styles

@example

Detached(Color.new, :red, :bold).call("hello")
# => "\e[31mhello\e[0m"

@param [String] value

the stirng to decorate with styles

@return [String]

@api public

# File lib/pastel/detached.rb, line 32
def call(*args)
  value = args.join
  @color.decorate(value, *styles)
end
Also aliased as: []
eql?(other) click to toggle source

Compare detached objects for equality of attributes

@return [Boolean]

@api public

# File lib/pastel/detached.rb, line 48
def eql?(other)
  instance_of?(other.class) && styles.eql?(other.styles)
end
hash() click to toggle source

Hash for this instance and its attributes

@return [Numeric]

@api public

# File lib/pastel/detached.rb, line 75
def hash
  [self.class, styles].hash
end
inspect() click to toggle source

Inspect this instance attributes

@return [String]

@api public

# File lib/pastel/detached.rb, line 66
def inspect
  "#<#{self.class.name} styles=#{styles.inspect}>"
end
to_proc() click to toggle source

@api public

# File lib/pastel/detached.rb, line 39
def to_proc
  self
end