Tbpgr Blog

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

2014-05-01から1ヶ月間の記事一覧

TbpgrUtils | 追加要件 AttrEnumerable#include_attr? 追加

概要 追加要件 AttrEnumerable#include_attr? 追加 詳細 追加要件 AttrEnumerable#include_attr? 仕様 ・規約により、クラス名をスネークケースにしたArrayのAttributesを持つこと ・Attributesの任意のメンバ変数の先頭の要素を指定した数取得 ※より詳細に…

Ruby | Kernel | spawn

概要 Kernel#spawn(command, options={}) -> Integer Kernel#spawn(env, command, options={}) -> Integer 詳細 引数を外部コマンドとして実行しますが、生成した 子プロセスの終了を待ち合わせません。 生成した子プロセスのプロセスIDを返します。 サンプ…

TbpgrUtils | 追加要件 AttrEnumerable#first_attr 追加

概要 追加要件 AttrEnumerable#first_attr 追加 詳細 追加要件 AttrEnumerable#first_attr 仕様 ・規約により、クラス名をスネークケースにしたArrayのAttributesを持つこと ・Attributesの任意のメンバ変数の先頭の要素を指定した数取得 ※より詳細について…

Ruby | CLI | Delight Casual Users | Choosing the Best Default Output Format Based on Context

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Delight Casual Users 詳細 ls はコンテキストに合わせてベストなデフォルト値を適用しています。 ls をオプションなしで、単独実行した場合は 下記のように、人間向けのフォーマットになり…

Ruby | CLI | Delight Casual Users | Preventing Destructive Actions by Default

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Delight Casual Users 詳細 UNIXの rm は破壊的なコマンドの良い例です。 rm は指定ファイルを削除します。デフォルトの rm はHelpfulなだけではなく、破壊的ではありません。 rm のみだと削…

Ruby | CLI | Delight Casual Users | Deciding Default Behavior

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Delight Casual Users 詳細 アプリケーションのデフォルトの振る舞いは、オプションを省略した際の動作です。 適切なデフォルトの振る舞いを選ぶことは、アプリケーションが何をするか、に依…

Ruby | CLI | Delight Casual Users | Default Values for the App's Arguments

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Delight Casual Users 詳細 多くのコマンドラインは引数としてファイルリストや標準入力を使用します。 その際に、入力があれば引数から値を取得。 入力がなければ標準入力から値を取得する…

Ruby | Kernel | sleep

概要 Kernel#sleep -> Integer Kernel#sleep(sec) -> Integer 詳細 ec 秒だけプログラムの実行を停止します。sec が省略された場合、他スレッドからの Thread#run などで明示的に起こさない限り永久にスリープします。 Thread#runを呼ぶとその時点で sleepの…

TbpgrUtils | 追加要件 AttrEnumerable#delete_attr 追加

概要 追加要件 AttrEnumerable#delete_attr 追加 詳細 追加要件 AttrEnumerable#delete_attr 仕様 ・規約により、クラス名をスネークケースにしたArrayのAttributesを持つこと ・Attributesの任意のメンバ変数が引数で指定の場合に該当要素を削除します、 ※…

Ruby | CLI | Delight Casual Users | Flag Arguments That Control Output Formatting

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Delight Casual Users 詳細 フラグの典型的な利用方法として出力フォーマットの変更がある。 典型的なのはアプリケーション向けの標準フォーマットと人間向けのPrettyフォーマット。どちらを…

Ruby | CLI | Delight Casual Users | Default Values for Flags

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Delight Casual Users 詳細 ユーザーがコマンドを実行する際に毎回フラグを指定しなければならないのなら、 ユーザーフレンドリーではありません。デフォルト値の設定は設計の決定事項です。…

Ruby | CLI | Delight Casual Users | Naming Commands in a Command Suit

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Delight Casual Users 詳細 Command suit において全てのコマンドは簡潔で明確な名前を持つこと。 もし、意味をなすことができるならコマンドは短いニーモニックを持つのも良い。 良い例は l…

Ruby | CLI | Delight Casual Users | Choosing Names for Options and Commands

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Delight Casual Users 詳細 Short-form optionは何のためにあるか? => アプリケーションを使い慣れたユーザーが少ないタイプで素早く実行するため。Long-form optionは何のためにあるか? =…

Ruby | Kernel | require_relative

概要 require_relative(relative_feature) -> bool 詳細 Ruby ライブラリ relative_feature を現在のファイルからの相対パスでロードします。 拡張子補完を行い、 同じファイルの複数回ロードはしません。ライブラリのロードに成功した時には true を返し、…

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 の名前を(拡 張子も含めて) 変数 $…

TbpgrUtils | 追加要件 AttrEnumerable#compact_attr 追加

概要 追加要件 AttrEnumerable#compact_attr 追加 詳細 追加要件 AttrEnumerable#compact_attr 仕様 ・規約により、クラス名をスネークケースにしたArrayのAttributesを持つこと ・Attributesの任意のメンバ変数のうち、nilを除いた配列を取得する ※より詳細…