LoginSignup
2
0

More than 1 year has passed since last update.

Rubocopエラー「Useless assignment to variable」の解決例

Posted at

Rubocopエラー「Useless assignment to variable」の解決例

上記エラーを調べると、「使っていないローカル変数の定義がある」というエラーのようで
削除すれば解決するとの事でした。

しかし、今回はちゃんと使っている内容で、書き方の問題のようでした。
以下のように、if文などの後に明示的に使用している記載が必要とのことでした。

  def sampe(引数)
    price = if 条件1
               '¥-'
            elsif 条件2
               表示させる内容
            else
               表示させる内容
            end
  end

  def sample(引数)
    price = if 条件1
               '¥-'
            elsif 条件2
               表示させる内容
            else
               表示させる内容
            end

    price
  end

#priceをしっかりと明示させる

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0