12FF5B8

hico_horiuchiの技術系な覚え書き.

Rubyのハッシュの省略記法

今月から,サークルのプロジェクトでRuby on Railsで開発している.

そこで,Gitでpushする前にrubocopでコーディング規約のチェックをしていて,
spec/controllers/にもかけてみたら,以下のように怒られた.

$ bundle exec rubocop spec/controllers/         
Inspecting 3 files
..C

Offences:

spec/controllers/user_controller_spec.rb:18:25: C: Use the new Ruby 1.9 hash syntax.
    before { get :show, :id => 1 }
                        ^^^^^^

3 files inspected, 1 offence detected

Ruby 1.9の新しいハッシュ記法を使え」とのこと.
@clc_igu先輩に聞いたら教えてくれた.

# 古いハッシュの書き方
:id => 1
# 新しいハッシュの書き方
id: 1

これでrubocopに怒られなくなった.