Skip to content

Welcome to Tech by Example

Menu
  • Home
  • Posts
  • System Design Questions
Menu

Print/Output text in bold in Ruby Language

Posted on August 14, 2021August 14, 2021 by admin

Overview

ANSI escape codes can be used to output bold text in the console. Please note that

  • In MAC/Linux system terminal supports ANSI escape codes
  • Windows Command Prompt doesn’t support it. On windows, you can install Cygwin. ANSI escape codes work on that.

Program

class String
    def bold
        "\e[1m#{self}\e[22m" 
     end
end

puts "Bold String".bold

Output

©2025 Welcome to Tech by Example | Design: Newspaperly WordPress Theme