LoginSignup
4
4

More than 5 years have passed since last update.

gem coloredがおしゃれ

Posted at

GitLabでも利用されているのですが、gem coloredがおしゃれな感じなので紹介。

作者はGitHubの@defunktさんです。4年前から開発が止まってます。

止まっているから問題…という分けではなく、実装がもの凄く小さいのでもう開発する必要がないという意味で止まっています。

defunkt / colored

実装

colored / lib / colored.rb ここを見ると分かりますが、module Coloredを定義しStringにincludeしています。

なので、require 'colored' した後はStringクラスでmodule内のインスタンスメソッドを使う事ができるようになってます。

機能

gemの名前の通り、Stringの出力の色をしていすることが出来る様になります。

  >> puts "this is red".red

  >> puts "this is red with a blue background (read: ugly)".red_on_blue

  >> puts "this is red with an underline".red.underline

  >> puts "this is really bold and really blue".bold.blue

  >> logger.debug "hey this is broken!".red_on_yellow     # in rails

  >> puts Color.red "This is red" # but this part is mostly untested

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4