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
420
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
33
devise-two-factorを4.xから5.xに上げた話
znz
0
130
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
56
Ubuntuのriscv64版をqemuで動かした
znz
0
65
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
69
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
58
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
120
Rubyist Magazine Reboot
znz
0
160
History of Japanese Ruby reference manual, and future
znz
0
1.6k
Other Decks in Technology
See All in Technology
『衛星データ利用の方々にとって近いようで触れる機会のなさそうな小話 ~ 衛星搭載ソフトウェアと衛星運用ソフトウェア (実物) を動かしながらわいわいする編 ~』 @日本衛星データコミニティ勉強会
meltingrabbit
0
150
人はなぜISUCONに夢中になるのか
kakehashi
PRO
6
1.7k
ユーザーストーリーマッピングから始めるアジャイルチームと並走するQA / Starting QA with User Story Mapping
katawara
0
210
Classmethod AI Talks(CATs) #17 司会進行スライド(2025.02.19) / classmethod-ai-talks-aka-cats_moderator-slides_vol17_2025-02-19
shinyaa31
0
130
個人開発から公式機能へ: PlaywrightとRailsをつなげた3年の軌跡
yusukeiwaki
11
3k
Amazon S3 Tablesと外部分析基盤連携について / Amazon S3 Tables and External Data Analytics Platform
nttcom
0
140
管理者しか知らないOutlookの裏側のAIを覗く#AzureTravelers
hirotomotaguchi
2
440
Classmethod AI Talks(CATs) #16 司会進行スライド(2025.02.12) / classmethod-ai-talks-aka-cats_moderator-slides_vol16_2025-02-12
shinyaa31
0
110
PHPカンファレンス名古屋-テックリードの経験から学んだ設計の教訓
hayatokudou
2
410
Moved to https://speakerdeck.com/toshihue/presales-engineer-career-bridging-tech-biz-ja
toshihue
2
750
RECRUIT TECH CONFERENCE 2025 プレイベント【高橋】
recruitengineers
PRO
0
160
Helm , Kustomize に代わる !? 次世代 k8s パッケージマネージャー Glasskube 入門 / glasskube-entry
parupappa2929
0
250
Featured
See All Featured
Embracing the Ebb and Flow
colly
84
4.6k
Adopting Sorbet at Scale
ufuk
74
9.2k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
630
Designing for Performance
lara
604
68k
Agile that works and the tools we love
rasmusluckow
328
21k
Done Done
chrislema
182
16k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Practical Orchestrator
shlominoach
186
10k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Speed Design
sergeychernyshev
27
790
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