Created
February 28, 2014 18:52
-
-
Save hiroshiro/b6cfa342ffedbdc7ebb0 to your computer and use it in GitHub Desktop.
使わないブロックパラメータには'_'をつける。Rubyの構文、良い、悪い例。
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
# bad | |
result = hash.map { |k, v| v + 1 } | |
def something(x) | |
unused_var, used_var = something_else(x) | |
# ... | |
end | |
# good | |
result = hash.map { |_k, v| v + 1 } | |
def something(x) | |
_unused_var, used_var = something_else(x) | |
# ... | |
end | |
# good | |
result = hash.map { |_, v| v + 1 } | |
def something(x) | |
_, used_var = something_else(x) | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prefix with _ unused block parameters and local variables. It's also acceptable to use just _ (although it's a bit less descriptive). This convention is recognized by the Ruby interpreter and tools like RuboCop and will suppress their unused variable warnings.