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
1
420
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
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
41
devise-two-factorを4.xから5.xに上げた話
znz
0
160
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
61
Ubuntuのriscv64版をqemuで動かした
znz
0
73
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
76
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
65
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
120
Rubyist Magazine Reboot
znz
0
180
History of Japanese Ruby reference manual, and future
znz
0
1.6k
Other Decks in Technology
See All in Technology
製造業の会計システムをDDDで開発した話
caddi_eng
3
1k
Restarting_SRE_Road_to_SRENext_.pdf
_awache
1
200
Riverpod & Riverpod Generatorを利用して状態管理部分の処理を書き換えてみる簡単な事例紹介
fumiyasac0921
0
110
数百台のオンプレミスのサーバーをEKSに移行した話
yukiteraoka
0
740
一人QA時代が終わり、 QAチームが立ち上がった話
ma_cho29
0
300
Road to SRE NEXT@仙台 IVRyの組織の形とSLO運用の現状
abnoumaru
1
420
ウェブアクセシビリティとは
lycorptech_jp
PRO
0
330
入社後SREチームのミッションや課題の整理をした話
morix1500
1
150
Multitenant 23ai の全貌 - 機能・設計・実装・運用からマイクロサービスまで
oracle4engineer
PRO
2
130
Amazon GuardDuty Malware Protection for Amazon S3を使おう
ryder472
2
110
コード品質向上で得られる効果と実践的取り組み
ham0215
2
210
小さく始めるDevOps 内製化支援から見えたDevOpsの始め方 / 20250317 Ken Takayanagi
shift_evolve
1
110
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1369
200k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
31
4.8k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
Why Our Code Smells
bkeepers
PRO
336
57k
The Cult of Friendly URLs
andyhume
78
6.3k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
BBQ
matthewcrist
88
9.5k
Being A Developer After 40
akosma
90
590k
Building an army of robots
kneath
304
45k
Thoughts on Productivity
jonyablonski
69
4.5k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Practical Orchestrator
shlominoach
186
10k
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