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
460
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
34
riscv64.rubyci.org internal
znz
0
30
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
71
devise-two-factorを4.xから5.xに上げた話
znz
0
350
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
87
Ubuntuのriscv64版をqemuで動かした
znz
0
110
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
110
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
100
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
160
Other Decks in Technology
See All in Technology
AWS re:Invent 2025 で頻出の 生成 AI サービスをおさらい
komakichi
3
240
2025 DORA Reportから読み解く!AIが映し出す、成果を出し続ける組織の共通点 #開発生産性_findy
takabow
0
130
個人から巡るAI疲れと組織としてできること - AI疲れをふっとばせ。エンジニアのAI疲れ治療法 ショートセッション -
kikuchikakeru
5
1.9k
AS59105におけるFreeBSD EtherIPの運用と課題
x86taka
0
270
変わるもの、変わらないもの :OSSアーキテクチャで実現する持続可能なシステム
gree_tech
PRO
0
850
身近なCSVを活用する!AWSのデータ分析基盤アーキテクチャ
koosun
0
4.1k
DDD x Microservice Architecture : Findy Architecture Conf 2025
syobochim
13
4.9k
AWS Media Services 最新サービスアップデート 2025
eijikominami
0
120
How We Built a Secure Sandbox Platform for AI
flatt_security
1
110
LINEスキマニ/LINEバイトにおけるバックエンド開発
lycorptech_jp
PRO
0
390
クラウドネイティブ時代の 開発プロセス再設計 〜速さと品質を両立するには〜
moritamasami
0
120
事業状況で変化する最適解。進化し続ける開発組織とアーキテクチャ
caddi_eng
1
7.5k
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
Why You Should Never Use an ORM
jnunemaker
PRO
60
9.6k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
Testing 201, or: Great Expectations
jmmastey
46
7.8k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Into the Great Unknown - MozCon
thekraken
40
2.2k
Large-scale JavaScript Application Architecture
addyosmani
514
110k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
How to train your dragon (web standard)
notwaldorf
97
6.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Producing Creativity
orderedlist
PRO
348
40k
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