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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
AWS Network Firewall Proxyを触ってみた
nagisa53
1
240
Context Engineeringの取り組み
nutslove
0
380
Amazon S3 Vectorsを使って資格勉強用AIエージェントを構築してみた
usanchuu
4
450
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
150
小さく始めるBCP ― 多プロダクト環境で始める最初の一歩
kekke_n
1
520
2026年、サーバーレスの現在地 -「制約と戦う技術」から「当たり前の実行基盤」へ- /serverless2026
slsops
2
260
~Everything as Codeを諦めない~ 後からCDK
mu7889yoon
3
470
Frontier Agents (Kiro autonomous agent / AWS Security Agent / AWS DevOps Agent) の紹介
msysh
3
180
SREのプラクティスを用いた3領域同時 マネジメントへの挑戦 〜SRE・情シス・セキュリティを統合した チーム運営術〜
coconala_engineer
2
740
Context Engineeringが企業で不可欠になる理由
hirosatogamo
PRO
3
650
10Xにおける品質保証活動の全体像と改善 #no_more_wait_for_test
nihonbuson
PRO
2
330
FinTech SREのAWSサービス活用/Leveraging AWS Services in FinTech SRE
maaaato
0
130
Featured
See All Featured
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1.1k
Exploring anti-patterns in Rails
aemeredith
2
250
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
200
Optimizing for Happiness
mojombo
379
71k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
The Curse of the Amulet
leimatthew05
1
8.7k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
130
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
150
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
440
Documentation Writing (for coders)
carmenintech
77
5.3k
Practical Orchestrator
shlominoach
191
11k
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