Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
How to specify `frozen_string_literal: true`
Search
Kazuhiro NISHIYAMA
September 19, 2017
Technology
1
460
How to specify `frozen_string_literal: true`
RubyKaigi 2017 の LT での発表資料です。
Kazuhiro NISHIYAMA
September 19, 2017
Tweet
Share
More Decks by Kazuhiro NISHIYAMA
See All by Kazuhiro NISHIYAMA
Ruby on Rails と私
znz
0
40
riscv64.rubyci.org internal
znz
0
39
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
77
devise-two-factorを4.xから5.xに上げた話
znz
0
370
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
91
Ubuntuのriscv64版をqemuで動かした
znz
0
110
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
110
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
110
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
160
Other Decks in Technology
See All in Technology
_第4回__AIxIoTビジネス共創ラボ紹介資料_20251203.pdf
iotcomjpadmin
0
170
Eight Engineering Unit 紹介資料
sansan33
PRO
0
6.1k
ESXi のAIOps だ!2025冬
unnowataru
0
470
スクラムを一度諦めたチームにアジャイルコーチが入ってどう変化したか
kyamashiro73
0
160
製造業から学んだ「本質を守り現場に合わせるアジャイル実践」
kamitokusari
0
290
Qiita Bash アドカレ LT #1
okaru
0
170
AI with TiDD
shiraji
1
340
善意の活動は、なぜ続かなくなるのか ーふりかえりが"構造を変える判断"になった半年間ー
matsukurou
0
240
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
5
1.5k
Bedrock AgentCore Evaluationsで学ぶLLM as a judge入門
shichijoyuhi
2
320
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1k
AI: The stuff that nobody shows you
jnunemaker
PRO
1
150
Featured
See All Featured
Navigating Team Friction
lara
191
16k
Optimizing for Happiness
mojombo
379
70k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
0
51
Optimising Largest Contentful Paint
csswizardry
37
3.6k
New Earth Scene 8
popppiees
0
1.3k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
35
The #1 spot is gone: here's how to win anyway
tamaranovitovic
1
880
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
0
400
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
The Cost Of JavaScript in 2023
addyosmani
55
9.4k
Transcript
How to specify frozen_string_literal: true Kazuhiro NISHIYAMA RubyKaigi 2017 LT
2017/09/19 Powered by Rabbit 2.2.1
self.introduce One of Ruby committers Twitter, GitHub: @znz 1/12
What’s frozen_string_literal magic comment Specify string literals are frozen or
not per fle Frozen string literals are faster Generate less objects Reduce GC 2/12
Example After coding if exist example: # -*- coding: utf-8
-*- # frozen_string_literal: true p ''.frozen? #=> true 3/12
Past release Add frozen_string_literal: false for almost *.rb fles when
Ruby 2.3.0 For compatibility with --enable=frozen-string- literal command line option of ruby 4/12
Changes in this year Recent Ruby programs tend to specify
true, but ruby standard libraries are false. So I changed to frozen_string_literal: true in some fles which assigned to no maintainer in doc/ maintainers.rdoc. 5/12
Review points before change Almost RuntimeError: can't modify frozen String
points are: String#<< bang methods (e.g. String#sub!) 6/12
Overlooked modifcation IO#read(length, out_buffer) this buffer is overlooked 7/12
Find modifed string literal --debug=frozen-string-literal command line option is very
useful examples: ruby --debug=frozen-string-literal test.rb make test-all TESTS='-v base64' RUBYOPT=--debug=frozen-string-literal 8/12
Tests --debug=frozen-string-literal needs to run codes. So tests are very
important. 9/12
No change if can’t If no tests, there is no
need to forcibly change it. I think working codes are useful than broken faster codes. 10/12
mkmf.rb mkmf.rb has many tests But mkmf.rb is too complex
to me in a short time So I remain false 11/12
Conclusion No tests may overlook modifcations Use frozen_string_literal: true if
you can You can use frozen_string_literal: false in some cases for compatibility for --enable=frozen- string-literal 12/12 Powered by Rabbit 2.2.1