LoginSignup
25
24

More than 5 years have passed since last update.

syntax_fixでRubyの古いHash記法を1.9スタイルに一括置換する

Posted at

問題

実行環境はRuby 1.9(または2.0)なのに、コード上では新旧のHash記法が混在して美しくない。

# 古い記法
:key => 'value'
# 新しい記法(Ruby 1.9以降)
key: 'value'

解決策

syntax_fixというGemを使うと簡単に一括置換できます。

対象となる拡張子は 'rb', 'erb', 'rake', 'haml' です。

$ gem install syntax_fix
$ rbenv rehash # rbenvを使っている場合
$ cd your-app-dir
$ syntax_fix -v # -vオプションで進行状況が表示される
Reading files...
/your-app-dir/config/application.rb [CHANGED]
/your-app-dir/config/routes.rb [CHANGED]
/your-app-dir/db/schema.rb [CHANGED]
.
.
.
Done!
$ git diff # 念のため変更内容を確認

注意

変換後のテスト実行もお忘れなく!!

25
24
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
25
24