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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Kazuhiro NISHIYAMA
September 19, 2017
Technology
480
1
Share
How to specify `frozen_string_literal: true`
RubyKaigi 2017 の LT での発表資料です。
Kazuhiro NISHIYAMA
September 19, 2017
More Decks by Kazuhiro NISHIYAMA
See All by Kazuhiro NISHIYAMA
Rubyの配布パッケージの変遷
znz
0
5
Headscale + Tailscale に移行中
znz
0
54
Ruby on Rails と私
znz
0
68
riscv64.rubyci.org internal
znz
0
56
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
110
devise-two-factorを4.xから5.xに上げた話
znz
0
400
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
110
Ubuntuのriscv64版をqemuで動かした
znz
0
140
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
140
Other Decks in Technology
See All in Technology
【関西製造業祭り2026春】現場を変える技術はここまで来た〜世界最大の製造業見本市から持って帰ってきたもの〜
tanakaseiya
0
180
AIAgentと取り組むKaggle
508shuto
2
300
Swift Sequence の便利 API 再発見
treastrain
1
290
既存プロダクトQAから新規プロダクトQAへ
ryotakahashi
0
160
The Bag-of-Documents Model for Query Understanding and Retrieval
dtunkelang
0
160
セキュリティ対策、何からはじめる? CloudNative環境の脅威モデリングと リスク評価実践入門 #cloudnativekaigi
varu3
5
990
AI全盛の今だからこそ、あえてもう一度振り返るAPIの基礎
smt7174
3
130
可視化から活用へ — Mesh化・Segmentation・アライメントの研究動向
gpuunite_official
0
230
なぜ、IAMロールのプリンシパルに*による部分マッチングが使えないのか? / 20260518-ssmjp-iam-role-principal
opelab
1
130
GCASアップデート(202603-202605)
techniczna
0
220
そのSLO 99.9%、本当に必要ですか? 〜優先度付きSLOによる責任共有の設計思想〜 / Is that 99.9% SLO really necessary? Design philosophy of shared responsibility through prioritized SLOs
vtryo
0
810
Purview Endpoint DLP 動かしてみた
kozakigh
0
440
Featured
See All Featured
Un-Boring Meetings
codingconduct
0
290
Become a Pro
speakerdeck
PRO
31
5.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.6k
Design in an AI World
tapps
1
210
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
55k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
370
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
200
Building Adaptive Systems
keathley
44
3k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
180
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