This is IT

技術、日常

()はメソッドから離すな

以下の2つのコード。どちらがエラー出るコードか分かるでしょうか

# No.1
assert_equal ({ all_files: false, sort_in_reverse: false, long_format: false }, option.load)

# No.2
assert_equal({ all_files: false, sort_in_reverse: false, long_format: false }, option.load)

そうです。No.1がエラーとなります。

syntax error, unexpected ':', expecting '}'
assert_equal { all_files: false, sort_in_reverse: false, long_format: false }, option.load

理由はタイトルの通り。assert_equalだってメソッドです。

普段は気付けられるのですが、今回のようにMinitestであったり、フレームワークを利用して見知らぬメソッドを使うときには注意。