LoginSignup
13
10

More than 5 years have passed since last update.

Rails Console上で出力を整形してくれるHirbが便利

Last updated at Posted at 2015-09-17

以下はRails Console上でusersテーブルから1件だけ取得するクエリだが、結果が少々見づらい。

irb(main):001:0> User.first
  User Load (0.3ms)  SELECT  `users`.* FROM `users`  ORDER BY `users`.`id` ASC LIMIT 1
=> #<User id: 1, status: "active", lock_version: 0, created_at: "2015-08-03 10:25:35 +0900", updated_at: "2015-08-03 10:25:35 +0900">
irb(main):002:0>

そこで、出力結果を整形してくれるHirbというgemを導入してみる。

インストール

Gemfileに以下を記述。

gem 'hirb'
gem 'hirb-unicode'

bundle installを実行。

$ bundle install

Hirbを有効にして、先程と同じクエリを実行してみる。
Rails Console上で以下を実行。

irb(main):002:0> Hirb.enable
=> true
irb(main):003:0> User.first
  User Load (0.3ms)  SELECT  `users`.* FROM `users`  ORDER BY `users`.`id` ASC LIMIT 1
+----+--------+--------------+---------------------------+---------------------------+
| id | status | lock_version | created_at                | updated_at                |
+----+--------+--------------+---------------------------+---------------------------+
| 1  | active | 0            | 2015-08-03 10:25:35 +0900 | 2015-08-03 10:25:35 +0900 |
+----+--------+--------------+---------------------------+---------------------------+
1 row in set
irb(main):004:0>

見やすい。

13
10
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
13
10