Last active
December 31, 2017 07:13
-
-
Save vochicong/8b11ddf0f95062fe257f9fae76a905f3 to your computer and use it in GitHub Desktop.
rubocop 0.51のStyle/SafeNavigation (&.)の重大バグ ref: https://qiita.com/vochicong/items/8f21d6045fab0d87f4fe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rubocop v0.51 の変換結果、正しい | |
if user&.group&.admin? | |
puts 'userが管理者です' | |
else | |
puts 'userがnilか、管理者ではないです' | |
end | |
# rubocop v0.51は以下の様に間違って変換 | |
if !user&.group&.admin? | |
puts 'userが普通ユーザです' | |
else | |
puts 'userがnilか、管理者です' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rubocop v0.52 の変換結果、v0.51同様で正しい | |
if user&.group&.admin? | |
puts 'userが管理者です' | |
else | |
puts 'userがnilか、管理者ではないです' | |
end | |
# rubocop v0.52 は以下を変更しなかった(正しい判断) | |
if user && !user.group.admin? | |
puts 'userが普通ユーザです' | |
else | |
puts 'userがnilか、管理者です' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if user && user.group.admin? | |
puts 'userが管理者です' | |
else | |
puts 'userがnilか、管理者ではないです' | |
end | |
if user && !user.group.admin? | |
puts 'userが普通ユーザです' | |
else | |
puts 'userがnilか、管理者です' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment