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
31
Ruby on Rails と私
znz
0
55
riscv64.rubyci.org internal
znz
0
45
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
88
devise-two-factorを4.xから5.xに上げた話
znz
0
380
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
98
Ubuntuのriscv64版をqemuで動かした
znz
0
120
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
120
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
120
Other Decks in Technology
See All in Technology
LINE Messengerの次世代ストレージ選定
lycorptech_jp
PRO
19
7.3k
OCI Security サービス 概要
oracle4engineer
PRO
2
13k
入門DBSC
ynojima
0
130
Databricksアシスタントが自分で考えて動く時代に! エージェントモード体験もくもく会
taka_aki
0
310
オンプレとGoogle Cloudを安全に繋ぐための、セキュア通信の勘所
waiwai2111
3
1.1k
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.4k
Agentic Codingの実践とチームで導入するための工夫
lycorptech_jp
PRO
0
400
男(監査)はつらいよ - Policy as CodeからAIエージェントへ
ken5scal
5
720
Oracle Cloud Infrastructure:2026年2月度サービス・アップデート
oracle4engineer
PRO
0
210
作るべきものと向き合う - ecspresso 8年間の開発史から学ぶ技術選定 / 技術選定con findy 2026
fujiwara3
7
2k
生成AIの利用とセキュリティ /gen-ai-and-security
mizutani
0
1k
Exadata Fleet Update
oracle4engineer
PRO
0
1.3k
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
470
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
130
Navigating Team Friction
lara
192
16k
Practical Orchestrator
shlominoach
191
11k
Darren the Foodie - Storyboard
khoart
PRO
3
2.7k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.8k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
140
Chasing Engaging Ingredients in Design
codingconduct
0
130
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
67
37k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
170
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
80
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