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
470
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
Headscale + Tailscale に移行中
znz
0
22
Ruby on Rails と私
znz
0
49
riscv64.rubyci.org internal
znz
0
44
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
84
devise-two-factorを4.xから5.xに上げた話
znz
0
380
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
95
Ubuntuのriscv64版をqemuで動かした
znz
0
110
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
120
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
120
Other Decks in Technology
See All in Technology
Why Organizations Fail: ノーベル経済学賞「国家はなぜ衰退するのか」から考えるアジャイル組織論
kawaguti
PRO
1
160
15 years with Rails and DDD (AI Edition)
andrzejkrzywda
0
200
Cosmos World Foundation Model Platform for Physical AI
takmin
0
960
クレジットカード決済基盤を支えるSRE - 厳格な監査とSRE運用の両立 (SRE Kaigi 2026)
capytan
6
2.8k
20260204_Midosuji_Tech
takuyay0ne
1
160
顧客との商談議事録をみんなで読んで顧客解像度を上げよう
shibayu36
0
280
Agile Leadership Summit Keynote 2026
m_seki
1
660
Ruby版 JSXのRuxが気になる
sansantech
PRO
0
160
OpenShiftでllm-dを動かそう!
jpishikawa
0
140
SRE Enabling戦記 - 急成長する組織にSREを浸透させる戦いの歴史
markie1009
0
150
22nd ACRi Webinar - NTT Kawahara-san's slide
nao_sumikawa
0
100
会社紹介資料 / Sansan Company Profile
sansan33
PRO
15
400k
Featured
See All Featured
Accessibility Awareness
sabderemane
0
56
Why Our Code Smells
bkeepers
PRO
340
58k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
94
Ethics towards AI in product and experience design
skipperchong
2
200
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
440
A Soul's Torment
seathinner
5
2.3k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
3.9k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
1.9k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
830
Building Adaptive Systems
keathley
44
2.9k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
320
How to train your dragon (web standard)
notwaldorf
97
6.5k
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