# Source: https://docs.datadoghq.com/security/code_security/static_analysis/static_analysis_rules/ruby-best-practices/trailing-underscore-variables.md

---
title: Do not use trailing underscores in destructuring assignments
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Do not use trailing underscores in destructuring assignments
---

# Do not use trailing underscores in destructuring assignments

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `ruby-best-practices/trailing-underscore-variables`

**Language:** Ruby

**Severity:** Notice

**Category:** Best Practices

## Description{% #description %}

The rule of not using trailing underscores in destructuring assignments in Ruby is important for the readability and maintainability of your code. Destructuring assignments are a powerful feature of Ruby that allow you to assign multiple variables at once from an array or hash. However, using trailing underscores can make your code more difficult to read and understand, as it's not immediately clear what the underscores represent.

Trailing underscores are often used to indicate unused variables in destructuring assignments. While this can be useful in some cases, it can also lead to confusion and errors if used improperly. In addition, it can make your code harder to debug and maintain in the long run.

To avoid this, always use descriptive variable names in your destructuring assignments, even if they're not being used. If you have variables that you don't need, consider refactoring your code to eliminate them. Additionally, you can use the `_` character for a single unused variable, but avoid using it multiple times in the same assignment. This will make your code more readable and easier to maintain.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```ruby
one, two, _ = [1, 2, 3, 4, 5]
one, _, _ = [1, 2, 3, 4, 5]
one, *_ = [1, 2, 3, 4, 5]
one, _, *_ = [1, 2, 3, 4, 5]
one, *_, _ = [1, 2, 3, 4, 5]
_, two, _ = [1, 2, 3, 4, 5]
_, _ = [1, 2, 3, 4, 5]
```

## Compliant Code Examples{% #compliant-code-examples %}

```ruby
one = [1, 2, 3, 4, 5]
one, two = [1, 2, 3, 4, 5]
one, _, three = [1, 2, 3, 4, 5]
one, *_, five = [1, 2, 3, 4, 5]
_, two = [1, 2, 3, 4, 5]
_ = [1, 2, 3, 4, 5]

*one_to_four, _ = [1, 2, 3, 4, 5]
*one_to_three, four, _ = [1, 2, 3, 4, 5]
one, *two_to_four, _ = [1, 2, 3, 4, 5]

one, _two = [1, 2, 3, 4, 5]
one, _two, = [1, 2, 3, 4, 5]
one, *_rest = [1, 2, 3, 4, 5]
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}