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
410
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の日本語リファレンスマニュアルの現在と未来
znz
0
28
devise-two-factorを4.xから5.xに上げた話
znz
0
110
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
52
Ubuntuのriscv64版をqemuで動かした
znz
0
55
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
65
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
50
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
110
Rubyist Magazine Reboot
znz
0
150
History of Japanese Ruby reference manual, and future
znz
0
1.6k
Other Decks in Technology
See All in Technology
Amazon Q Developerで.NET Frameworkプロジェクトをモダナイズしてみた
kenichirokimura
1
190
2025年の挑戦 コーポレートエンジニアの技術広報/techpr5
nishiuma
0
130
【JAWS-UG大阪 reInvent reCap LT大会 サンバが始まったら強制終了】“1分”で初めてのソロ参戦reInventを数字で振り返りながら反省する
ttelltte
0
130
WantedlyでのKotlin Multiplatformの導入と課題 / Kotlin Multiplatform Implementation and Challenges at Wantedly
kubode
0
240
AWSの生成AIサービス Amazon Bedrock入門!(2025年1月版)
minorun365
PRO
7
450
AWSサービスアップデート 2024/12 Part3
nrinetcom
PRO
0
130
Accessibility Inspectorを活用した アプリのアクセシビリティ向上方法
hinakko
0
170
Cloudflareで実現する AIエージェント ワークフロー基盤
kmd09
0
280
2025年に挑戦したいこと
molmolken
0
140
アジャイルチームが変化し続けるための組織文化とマネジメント・アプローチ / Agile management that enables ever-changing teams
kakehashi
3
3.2k
なぜfreeeはハブ・アンド・スポーク型の データメッシュアーキテクチャにチャレンジするのか?
shinichiro_joya
2
140
チームが毎日小さな変化と適応を続けたら1年間でスケール可能なアジャイルチームができた話 / Building a Scalable Agile Team
kakehashi
2
210
Featured
See All Featured
For a Future-Friendly Web
brad_frost
176
9.5k
4 Signs Your Business is Dying
shpigford
182
22k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
jQuery: Nuts, Bolts and Bling
dougneiner
62
7.6k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Being A Developer After 40
akosma
89
590k
Why Our Code Smells
bkeepers
PRO
335
57k
Raft: Consensus for Rubyists
vanstee
137
6.7k
RailsConf 2023
tenderlove
29
970
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Fireside Chat
paigeccino
34
3.1k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.2k
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