Skip to content

Instantly share code, notes, and snippets.

@hiroshiro
Created February 28, 2014 18:52
Show Gist options
  • Save hiroshiro/b6cfa342ffedbdc7ebb0 to your computer and use it in GitHub Desktop.
Save hiroshiro/b6cfa342ffedbdc7ebb0 to your computer and use it in GitHub Desktop.
使わないブロックパラメータには'_'をつける。Rubyの構文、良い、悪い例。
# 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
@hiroshiro
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment