0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Missing frozen string literal comment. (convention:Style/FrozenStringLiteralComment)

Posted at

以下、ChatGPTの回答を要約

  • この警告は、RuboCopと呼ばれるRubyコードスタイルおよび品質のツールからのもので、Rubyコード内で "Frozen String Literal Comment" が見つからない場合に表示される。

  • "Frozen String Literal Comment" は、Ruby 2.3以降で導入された機能で、文字列(String)リテラルを凍結(freeze)させるための指示。

    • 文字列を凍結すると、その文字列への変更ができなくなり、メモリ使用量が削減されるなどの利点がある。

使い方

Rubyコード内の冒頭に、次のようにコメントを追加する。(=マジックコメント)

# frozen_string_literal: true

効果

# frozen_string_literal: true

message1 = "Hello, World!"  # 凍結されます
message2 = "Hello, World!"  # 凍結されます

# 同じ文字列のため、同じobject_idを持つ(=メモリ使用量が削減できる)
p message1.object_id # 60
p message2.object_id # 60
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?