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
Headscale + Tailscale に移行中
znz
0
44
Ruby on Rails と私
znz
0
63
riscv64.rubyci.org internal
znz
0
53
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
100
devise-two-factorを4.xから5.xに上げた話
znz
0
400
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
110
Ubuntuのriscv64版をqemuで動かした
znz
0
130
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
130
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
130
Other Decks in Technology
See All in Technology
Percolatorを廃止し、マルチ検索サービスへ刷新した話 / Search Engineering Tech Talk 2026 Spring
visional_engineering_and_design
0
140
「責任あるAIエージェント」こそ自社で開発しよう!
minorun365
9
2.2k
Pure Intonation on Browser: Building a Sequencer with Ruby
nagachika
0
150
AgentCore Managed Harness を使ってみよう
yakumo
2
220
Agents CLI と Gemini Enterprise Agent Platform で マルチエージェント開発が楽しくなる!
kaz1437
0
140
AI時代 に増える データ活用先
takahal
0
320
Anthropic「Long-running a gents」をGeminiで再現してみた
tkikuchi
0
160
[最強DB講義]推薦システム | 評価編
recsyslab
PRO
0
100
Cortex Codeのコスト見積ヒントご紹介
yokatsuki
0
110
AIが書いたコードを信じられない問題 〜レビュー負荷を下げるために変えたこと〜 / The AI Code Trust Gap: Reducing the Review Burden
bitkey
PRO
8
1.4k
エージェントスキルを作って自分のインプットに役立てよう
tsubakimoto_s
0
440
ネットワーク運用を楽にするAWS DevOps Agent活用法!! / 20260421 Masaki Okuda
shift_evolve
PRO
2
220
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
320
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
490
Building the Perfect Custom Keyboard
takai
2
730
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Skip the Path - Find Your Career Trail
mkilby
1
110
Speed Design
sergeychernyshev
33
1.6k
A Soul's Torment
seathinner
6
2.7k
How STYLIGHT went responsive
nonsquared
100
6.1k
GitHub's CSS Performance
jonrohan
1032
470k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
170
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
150
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
210
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