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
500
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
46
Headscale + Tailscale に移行中
znz
0
87
Ruby on Rails と私
znz
0
88
riscv64.rubyci.org internal
znz
0
66
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
120
devise-two-factorを4.xから5.xに上げた話
znz
0
450
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
120
Ubuntuのriscv64版をqemuで動かした
znz
0
150
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
160
Other Decks in Technology
See All in Technology
Does an AI Watermark Survive Translation?
machinetranslation
0
510
markdown-poster Introduction
kazamori
0
440
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3.2k
AIエージェントのためのデータ設計
daiz21
0
570
暗号化?某ファイルストレージはどうなるの!? 3rd Partyとうまく付き合う秘密度ラベル設計
kasada
0
220
顧客の要望は2次情報である 〜アンテナを張るFDEの構造論〜
noriakioji
5
1.1k
Guerilla InnerSource in enterprises, during the AI hype
onenashev
PRO
0
130
承認ゲートは何を守っているのか? AIエージェントの自律購入を実測した結果
yama3133
1
100
魔法少女がClaude Codeを監視する / ccportal-deck
noriyukitakei
3
100
全社に広がるMCPサーバーを、 どう安全に管理するか MCPass開発の舞台裏
mtpooh
3
210
Level Up Your CDK DX: 5 Tools I’ve Been Building
gotok365
2
140
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
54k
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
How to make the Groovebox
asonas
2
2.4k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Skip the Path - Find Your Career Trail
mkilby
1
210
Code Reviewing Like a Champion
maltzj
528
40k
A Soul's Torment
seathinner
7
3.5k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
220
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
430
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
260
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
310
ラッコキーワード サービス紹介資料
rakko
1
4.6M
Raft: Consensus for Rubyists
vanstee
141
7.7k
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