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
490
1
Share
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
16
Headscale + Tailscale に移行中
znz
0
57
Ruby on Rails と私
znz
0
72
riscv64.rubyci.org internal
znz
0
58
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
110
devise-two-factorを4.xから5.xに上げた話
znz
0
410
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
110
Ubuntuのriscv64版をqemuで動かした
znz
0
140
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
140
Other Decks in Technology
See All in Technology
探して_入れて_作って_使う_Agent_Skills___LT.pdf
peintangos
2
130
「嘘をつくテスト」の失敗例から学ぶ 良いテストコード #frontend_phpcon_do
asumikam
0
110
Fabric-cicd によるAzure DevOps デプロイ
ryomaru0825
0
170
20260528_生成AIを専属DSに_Howの次にすべきことを考える
doradora09
PRO
0
270
Diagnosing performance problems without the guesswork
elenatanasoiu
0
130
ITエンジニアを取り巻く環境とキャリアパス / A career path for Japanese IT engineers
takatama
4
1.8k
『家族アルバム みてね』における インシデント対応との向き合い方 / Approach incident response in Family Album
kohbis
2
280
AI駆動開発でなんでもハンズオン環境をつくってみた
yoshimi0227
0
190
エンジニアは生成AIと どのように向き合うべきか? ことばの意味という観点から
verypluming
3
310
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
4
2.8k
【Gen-AX】20260530開催_JJUG CCC 2026 Spring
genax
0
170
Terraformモジュールは、なぜ「魔境」化するのか
hayama17
1
130
Featured
See All Featured
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
200
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
150
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
550
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
130
Designing Powerful Visuals for Engaging Learning
tmiket
1
390
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
300
Between Models and Reality
mayunak
4
320
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
710
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