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
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
Ruby on Rails と私
znz
0
41
riscv64.rubyci.org internal
znz
0
41
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
78
devise-two-factorを4.xから5.xに上げた話
znz
0
370
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
92
Ubuntuのriscv64版をqemuで動かした
znz
0
110
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
120
小規模個人アプリをRails 7.xにバージョンアップした話
znz
0
110
Ruby リファレンスマニュアル改善計画 2022 進捗報告
znz
0
170
Other Decks in Technology
See All in Technology
Scrum Guide Expansion Pack が示す現代プロダクト開発への補完的視点
sonjin
0
710
Introduction to Sansan Meishi Maker Development Engineer
sansan33
PRO
0
330
コミュニティが持つ「学びと成長の場」としての作用 / RSGT2026
ama_ch
2
320
Master Dataグループ紹介資料
sansan33
PRO
1
4.2k
たかがボタン、されどボタン ~button要素から深ぼるボタンUIの定義について~ / BuriKaigi 2026
yamanoku
1
280
SES向け、生成AI時代におけるエンジニアリングとセキュリティ
longbowxxx
0
320
「リリースファースト」の実感を届けるには 〜停滞するチームに変化を起こすアプローチ〜 #RSGT2026
kintotechdev
0
1k
Oracle Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
2
900
Databricks Free Edition講座 データエンジニアリング編
taka_aki
0
2.7k
手軽に作れる電卓を作って イベントソーシングに親しもう CQRS+ESカンファレンス2026
akinoriakatsuka
0
420
AWSと生成AIで学ぶ!実行計画の読み解き方とSQLチューニングの実践
yakumo
2
570
AIと融ける人間の冒険
pujisi
0
120
Featured
See All Featured
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
0
280
ラッコキーワード サービス紹介資料
rakko
0
2M
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
The Cult of Friendly URLs
andyhume
79
6.8k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Paper Plane
katiecoart
PRO
0
45k
KATA
mclloyd
PRO
33
15k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
0
1.8k
Code Reviewing Like a Champion
maltzj
527
40k
How to make the Groovebox
asonas
2
1.9k
Ruling the World: When Life Gets Gamed
codingconduct
0
120
Claude Code のすすめ
schroneko
67
210k
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