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
37
Headscale + Tailscale に移行中
znz
0
78
Ruby on Rails と私
znz
0
85
riscv64.rubyci.org internal
znz
0
64
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
120
devise-two-factorを4.xから5.xに上げた話
znz
0
440
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
120
Ubuntuのriscv64版をqemuで動かした
znz
0
150
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
150
Other Decks in Technology
See All in Technology
FDEの心得
noriakioji
0
240
【CEDEC2026】ゲームシナリオライターを支援するAIツール開発の実践 ― 設計とプロンプトの工夫 ―
cygames
PRO
1
780
MIRU 2026 チュートリアル
keisuke198619
0
880
取引先から届く 「セキュリティチェックシート」の読み解き方
kamadamakoto
0
140
FORENSIA: ローカルLLMフォレンジックハーネス
sumeshi
2
360
【CEDEC2026】次世代デジタルカードゲームのサーバー設計と運用 〜『Shadowverse: Worlds Beyond』の舞台裏~
cygames
PRO
1
1.1k
ガバメントクラウドでのランサムウェア対策
techniczna
2
1.1k
FPGAが実現する遠方宇宙の高空間分解能天体撮影 -大型地上望遠鏡の視力を補正する「補償光学」とは?-
komei_mt
0
210
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1.2k
【CEDEC2026】『GRANBLUE FANTASY: Relink - Endless Ragnarok』のバトル制作事例 ~最高のキャラゲーを目指して~
cygames
PRO
0
230
生成 AI の基礎 〜 サンプル実装で学ぶ基本原理
enakai00
7
4.4k
トヨタ⽣産⽅式(TPS)⼊⾨
recruitengineers
PRO
3
680
Featured
See All Featured
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
790
The Spectacular Lies of Maps
axbom
PRO
1
900
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.7k
The Pragmatic Product Professional
lauravandoore
37
7.4k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
470
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
Visualization
eitanlees
152
17k
Designing Experiences People Love
moore
143
24k
Utilizing Notion as your number one productivity tool
mfonobong
4
530
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
450
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
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