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
46
Headscale + Tailscale に移行中
znz
0
87
Ruby on Rails と私
znz
0
88
riscv64.rubyci.org internal
znz
0
66
Rubyの日本語リファレンスマニュアルの現在と未来
znz
0
120
devise-two-factorを4.xから5.xに上げた話
znz
0
450
docs.ruby-lang.org/ja/ の生成方法を変えた
znz
0
120
Ubuntuのriscv64版をqemuで動かした
znz
0
150
lilo.linux.or.jpをbusterからbullseyeに上げた
znz
0
160
Other Decks in Technology
See All in Technology
書籍『生成AIの安全性入門』の入門
wataoka
0
140
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
54k
『自分で判断できるか』を基準に、プロダクトのハンズオン研修でAI利用の線を引いてみた / Where We Drew the Line on AI in Hands-on Training
honyanya
1
510
本番に近いテストをもっと手軽に - Postmanで広がるAPIテストの世界 / Expanding the World of API Testing with Postman
yokawasa
1
180
Claude Teamプランの コスト最適化を考える
rfdnxbro
2
850
Genie Code ワークショップ 基礎編 / Genie-Code-Workshop-fundamental
databricksjapan
PRO
0
120
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3.2k
現場の暗黙知を継承するAIエージェント — 対話から生まれる長期記憶と Skills
atsukish
0
190
どんな手を使っても絶対間に合わせるスケジューラ
asari194617
0
1.5k
AWSとGitHub Actionsの責任境界と 組織で安全に使用する取り組み
nealle
1
240
Digital Credentials API × OpenID4VP ブラウザ完結型本人確認の実装知見(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
390
AI駆動開発はどこまで来たのか? ファインディの最新実態調査で読み解く現在地 Devin Con Tokyo
akiratom
4
2.2k
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.8k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
450
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
270
From π to Pie charts
rasagy
0
340
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
550
Scaling GitHub
holman
464
140k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Test your architecture with Archunit
thirion
2
2.4k
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