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
450
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
25
riscv64.rubyci.org internal
znz
0
21
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
68
devise-two-factorを4.xから5.xに上げた話
znz
0
330
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
84
Ubuntuのriscv64版をqemuで動かした
znz
0
100
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
110
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
96
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
150
Other Decks in Technology
See All in Technology
新規事業におけるGORM+SQLx併用アーキテクチャ
hacomono
PRO
0
220
Node.js 2025: What's new and what's next
ruyadorno
0
120
Git in Team
kawaguti
PRO
3
360
サイバーエージェント流クラウドコスト削減施策「みんなで金塊堀太郎」
kurochan
2
740
大規模サーバーレスAPIの堅牢性・信頼性設計 〜AWSのベストプラクティスから始まる現実的制約との向き合い方〜
maimyyym
9
4.4k
能登半島災害現場エンジニアクロストーク 【JAWS FESTA 2025 in 金沢】
ditccsugii
0
600
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
11
80k
やる気のない自分との向き合い方/How to Deal with Your Unmotivated Self
sanogemaru
0
500
成長自己責任時代のあるきかた/How to navigate the era of personal responsibility for growth
kwappa
4
320
AWS IoT 超入門 2025
hattori
0
330
「れきちず」のこれまでとこれから - 誰にでもわかりやすい歴史地図を目指して / FOSS4G 2025 Japan
hjmkth
1
300
能登半島地震において デジタルができたこと・できなかったこと
ditccsugii
0
170
Featured
See All Featured
Producing Creativity
orderedlist
PRO
347
40k
4 Signs Your Business is Dying
shpigford
185
22k
Six Lessons from altMBA
skipperchong
28
4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
61k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Making Projects Easy
brettharned
119
6.4k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
9
590
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
32
2.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
352
21k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.9k
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