Sha256: 57f2a437b5ebbffe0668c42d2d98bf7c0239af9c55d4957d7b3b23ca2932c068

Contents?: true

Size: 895 Bytes

Versions: 8

Compression:

Stored size: 895 Bytes

Contents

#  String Class extensions
class String
  # Outputs a string in a formatted color.
  # @param [<Integer, String>] color_code The code to use
  # @return [void]
  def colorize(color_code)
    "\033[#{ color_code }m#{ self }\033[0m"
  end

  # Makes the associated string blue.
  # @return [void]
  def blue
    colorize(34)
  end

  # Makes the associated string cyan.
  # @return [void]
  def cyan
    colorize(36)
  end

  # Makes the associated string green.
  # @return [void]
  def green
    colorize(32)
  end

  # Makes the associated string purple.
  # @return [void]
  def purple
    colorize(35)
  end

  # Makes the associated string red.
  # @return [void]
  def red
    colorize(31)
  end

  # Makes the associated string white.
  # @return [void]
  def white
    colorize(37)
  end

  # Makes the associated string yellow.
  # @return [void]
  def yellow
    colorize(33)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cliutils-1.3.1 lib/cliutils/ext/string_extensions.rb
cliutils-1.3.0 lib/cliutils/ext/string_extensions.rb
cliutils-1.2.9 lib/cliutils/ext/string_extensions.rb
cliutils-1.2.8 lib/cliutils/ext/string_extensions.rb
cliutils-1.2.7 lib/cliutils/ext/string_extensions.rb
cliutils-1.2.6 lib/cliutils/ext/string_extensions.rb
cliutils-1.2.5 lib/cliutils/ext/string_extensions.rb
cliutils-1.2.4 lib/cliutils/ext/string_extensions.rb