Tbpgr Blog

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

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

Ruby | Kernel | untrace_var

概要 Kernel#untrace_var(varname, hook = nil) 詳細 グローバル変数 varname に関連付けられたフックを解除します。 hook が指定された場合にはそのフックだけを解除します。 省略するか nil を与えた場合は varname のフックを全て解除します。 サンプルコ…

TbpgrUtils | 追加要件 AttrEnumerable#sample_attr 追加

概要 追加要件 AttrEnumerable#sample_attr 追加 詳細 追加要件 AttrEnumerable#sample_attr 仕様 ・規約により、クラス名をスネークケースにしたArrayのAttributesを持つこと ・Attributesの任意のメンバ変数を配列にし、Array#sampleと同様にランダムに要…

Ruby | Kernel | trace_var

概要 Kernel#trace_var(varname, hook) -> nil Kernel#trace_var(varname) {|new_val| .... } -> nil Kernel#trace_var(varname, hook) -> [String|Proc] 詳細 グローバル変数 varname への代入のフックを登録します。 ここでの「グローバル変数」は、特殊変…

TbpgrUtils | 追加要件 AttrEnumerable#reduce_attr 追加

概要 追加要件 AttrEnumerable#reduce_attr 追加 詳細 追加要件 AttrEnumerable#reduce_attr 仕様 ・規約により、クラス名をスネークケースにしたArrayのAttributesを持つこと ・Attributesの任意のメンバ変数を配列にし、Array#reduceと同様にブロックを実…

Build Awesome Command-Line Applications in Ruby2 書評

概要 Build Awesome Command-Line Applications in Ruby2 書評 詳細 Build Awesome Command-Line Applications in Ruby2 は RubyでAwesome = 素晴らしいCommand-Line Interface(以降CLI) アプリケーション(以降 App)を作る方法についてまとめてあります。以…

Ruby | CLI | Add Color Formatting and Interactivity | Formatting Output with Tables

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Add Color Formatting and Interactivity いつ表形式の出力を使うか レコードと列からなる大量のデータを扱う場合。 DBの表データが典型的な例。 他のアプリケーションが利用しやすいフォー…

Ruby | CLI | Add Color Formatting and Interactivity | Adding Color Using ANSI Escape Sequences

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Add Color Formatting and Interactivity いつ色付きの出力を使うか 状態を表す Cucumberは色を効果的に使ったCLI Toolの良い例です。 テストが失敗していれば、赤。 成功していれば緑で表示…

Ruby | CLI | Add Color Formatting and Interactivity

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Add Color Formatting and Interactivity 詳細 例えばCucumberはカラフルな出力でユーザーにテスト結果をわかりやすく伝えます。 例えばSQLクライアントはユーザーに優しい表形式の出力を行…

Ruby | CLI | Be Easy to Maintain

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Be Easy to Maintain 詳細 どのようにアプリケーションの複雑性の増加を防ぐか? アプリケーションをわかりやすく保つことは,アプリケーションの開発に協力してくれるくれる人を増やすのに役…

Ruby | Kernel | throw

概要 Kernel#throw(tag, value = nil) -> () 詳細 Kernel.#catchとの組み合わせで大域脱出を行います。 throw は同じ tag を指定した catch のブロックの終わりまでジャンプします。 tag はメソッド内とは限らない。 サンプルコード def pattern1 cnt = 0 ca…

TbpgrUtils | 追加要件 AttrEnumerable#map_attr 追加

概要 追加要件 AttrEnumerable#map_attr 追加 詳細 追加要件 AttrEnumerable#map_attr 仕様 ・規約により、クラス名をスネークケースにしたArrayのAttributesを持つこと ・Attributesの任意のメンバ変数を配列にし、Array#mapと同様にブロックを実行する。 ※…

Ruby | CLI | Make Configration Easy | Using Configuration File with Command Suites

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Make Configration Easy 詳細 Command Suitesのように複数のコマンドを持つ場合、コマンドごとの引数やオプションの設定が必要です。 サンプル仕様 下記記事のサンプルをベースに設定を追加…

Ruby | CLI | Make Configration Easy | Reading External Configuration from Files

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Make Configration Easy 詳細 外部設定ファイルを利用すると、ユーザーはコマンドラインの引数やオプションを与えることなく アプリケーションの振る舞いを制御できる。例えばあるオプション…

Ruby | CLI | Make Configration Easy | Why External Configuration?

概要 書籍 Build Awesome Command-Line Applications in Ruby2 章 Make Configration Easy 詳細 なぜ外部設定が必要になるのか?アプリケーションの基本的な振る舞いや、新規ユーザーが使いやすく・覚えやすいように作られるが、 パワーユーザーの複雑な作業…

Ruby | Kernel | test

概要 Kernel#test(cmd, file) -> bool | Time | Integer | nil Kernel#test(cmd, file1, file2) -> bool 詳細 Kernel#test(cmd, file)は単体のファイルでファイルテストを行います。 Kernel#test(cmd, file1, file2)は二つのファイルでファイルテストを行い…

TbpgrUtils | 追加要件 AttrEnumerable#last_attr 追加

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

Ruby | Kernel | srand

概要 Kernel#srand -> Integer Kernel#srand(seed) -> Integer 詳細 Kernel.#rand や Random.rand で使用される擬似乱数生成器の種を設定し、古い種を返します。 サンプルコード first = srand(6) print rand(1..10), ',', rand(1..10), ',', rand(1..10), "…