Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

2014-05-28から1日間の記事一覧

TbpgrUtils | 追加要件 AttrEnumerable#concat_attr 追加

概要 追加要件 AttrEnumerable#concat_attr 追加 詳細 追加要件 AttrEnumerable#concat_attr 仕様 ・規約により、クラス名をスネークケースにしたArrayのAttributesを持つこと ・Attributesの任意のメンバ変数からなる配列に、引数で指定した配列を結合しま…

Ruby | CLI | Play Well with Others | Trapping Signals Sent from Other Apps

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 長い処理を行うアプリケーションを作った場合などに、途中で処理を中止することがあります。 そのような際に行う処理を記述しておき、中途半端な処理にならない…

Ruby | CLI | Play Well with Others | Provide a Pretty-Printing Option

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 CLIアプリケーションは、他のアプリケーション向けの「機械的に読み取りやすいデータ」と 「人間が読みやすいデータ」の両面をサポートすることが重要です。この…

Ruby | CLI | Play Well with Others | Add Additional Fields to Make Searching Easier

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 ユーザーが対象データを抽出しやすいように、フラグやステータスを表す内容を レコードに含めることも有効。 サンプル仕様 引数1 〜 引数2 の範囲数値を配列化し…

Ruby | CLI | Play Well with Others | Format Output One Record per Line, Delimiting Fields

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 1レコード、デリミタ区切りのフィールドの構成にすることによって 後続のアプリケーションが加工しやすいフォーマットになります。 サンプル 引数1〜引数2の数値…

Ruby | CLI | Play Well with Others | Formatting Output for Use As Input Another Program

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 あるアプリケーションの出力が他のアプリケーションの入力になる例として、 ls と sort の組み合わせを見る。ls には数値順にソートする機能はない。 しかし、ls…

Ruby | CLI | Play Well with Others | Use STDOUT and STDERR to Send Output to the Correct Stream

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 標準出力はSTDOUTに、標準エラーはSTDERRに出力します。 標準エラーの出力には STDERR.puts "エラーメッセージ" warn "エラーメッセージ" の両方が利用できます…

Ruby | CLI | Play Well with Others | Using Open3 to Access the Standard Output and Error Streams Separately

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 Rubyではバッククォートもしくは、 %x[] によって標準出力を取得できるが 標準エラーは取得できない。標準エラーにもアクセスするには Open3ライブラリを利用す…

Ruby | CLI | Play Well with Others | Reporting Multiple Errors int the Exit

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 exit code は一つの数値しか取れません。 ビットマスクとして扱うことで各ビットに意味を持たせることができます、 サンプルコード 引数に応じて exit code を設…

Ruby | CLI | Play Well with Others | Sending Exit Codes to Calling Process

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 exit code の設定は非常にシンプルです。 Rubyは組み込みのメソッドとして exit メソッドを持っています。 引数を省略して exit すると、$? は 0 = 成功になりま…

Ruby | CLI | Play Well with Others | Accessing Exit Codes of Other Commands

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 $? という名前はBashをやっている人には慣れ親しんだ変数名だが その他人にはわかりにくい。 より人間に読みやすくするため、標準ライブラリの English を利用し…

Ruby | CLI | Play Well with Others | Using Exit Codes to Report Success or Failure

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 exit code はアプリケーション終了時の成否を伝える。 exit code が 0 なら成功。 それ以外なら失敗。シェルの $? にステータスが格納されています。 サンプル仕…

Ruby | CLI | Play Well with Others

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Play Well with Others 詳細 CLIアプリケーションを利用する直接のユーザーは利用者の一部。 利用者には他のCLIアプリケーションもいる。他のアプリケーションとコミュニケーションをとる手…

Ruby | CLI | Be Helpful | Documenting Everything Else

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Be Helpful 詳細 man page など、helpオプション以外のより詳細を記述するドキュメントについて。 このドキュメントはセクションによって分類されるべき。一般的なカテゴリは以下 カテゴリ …

Ruby | Kernel | require

概要 Kernel#require(feature) -> bool 詳細 Ruby ライブラリ feature をロードします。 拡張子補完を行い、 同じファイルの複数回ロードはしません。ライブラリのロードに成功した時には true を返し、ロードした feature の名前を(拡 張子も含めて) 変数 $…