Class: Pastel::Detached

Inherits:
Object
  • Object
show all
Defined in:
lib/pastel/detached.rb

Overview

A class representing detached color

Instance Method Summary collapse

Constructor Details

#initialize(color, *styles) ⇒ Detached

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.

Initialize a detached object

Parameters:

  • color (Pastel::Color)

    the color instance

  • styles (Array[Symbol])

    the styles to be applied



14
15
16
17
18
# File 'lib/pastel/detached.rb', line 14

def initialize(color, *styles)
  @color  = color
  @styles = styles.dup
  freeze
end

Instance Method Details

#==(other) ⇒ Boolean

Compare detached objects for equivalence of attributes

Returns:

  • (Boolean)


57
58
59
# File 'lib/pastel/detached.rb', line 57

def ==(other)
  other.is_a?(self.class) && styles == other.styles
end

#call(*args) ⇒ String Also known as: []

Decorate the values corresponding to styles

Examples:

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

Parameters:

  • value (String)

    the stirng to decorate with styles

Returns:

  • (String)


32
33
34
35
# File 'lib/pastel/detached.rb', line 32

def call(*args)
  value = args.join
  @color.decorate(value, *styles)
end

#eql?(other) ⇒ Boolean

Compare detached objects for equality of attributes

Returns:

  • (Boolean)


48
49
50
# File 'lib/pastel/detached.rb', line 48

def eql?(other)
  instance_of?(other.class) && styles.eql?(other.styles)
end

#hashNumeric

Hash for this instance and its attributes

Returns:

  • (Numeric)


75
76
77
# File 'lib/pastel/detached.rb', line 75

def hash
  [self.class, styles].hash
end

#inspectString

Inspect this instance attributes

Returns:

  • (String)


66
67
68
# File 'lib/pastel/detached.rb', line 66

def inspect
  "#<#{self.class.name} styles=#{styles.inspect}>"
end

#to_procObject



39
40
41
# File 'lib/pastel/detached.rb', line 39

def to_proc
  self
end