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
いつか使える ObjectSpace / Maybe useful ObjectSpace
Search
Shintani Teppei
September 05, 2024
Programming
2
260
いつか使える ObjectSpace / Maybe useful ObjectSpace
Omotesando.rb#101 の発表資料です。
https://omotesandorb.connpass.com/event/328438/
Shintani Teppei
September 05, 2024
Tweet
Share
More Decks by Shintani Teppei
See All by Shintani Teppei
「地続き」の技術面接 / "Continuous" technical interview
euglena1215
0
42
allow_retry と Arel.sql / allow_retry and Arel.sql
euglena1215
1
280
AIと”コードの評価関数”を共有する / Share the "code evaluation function" with AI
euglena1215
1
270
ISUCONで型をつける
euglena1215
1
150
3年でバックエンドエンジニアが5倍に増えても破綻しなかったアーキテクチャ そして、これから / Software architecture that scales even with a 5x increase in backend engineers in 3 years
euglena1215
11
5.6k
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
8
1.1k
rbs-inlineを導入してYARDからRBSに移行する
euglena1215
1
940
Ruby の型に関する活動をやっている話 / Activities related to Ruby types
euglena1215
3
420
そろそろ理解する includes / Understanding includes
euglena1215
1
1k
Other Decks in Programming
See All in Programming
L’IA au service des devs : Anatomie d'un assistant de Code Review
toham
0
150
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
420
Coding at the Speed of Thought: The New Era of Symfony Docker
dunglas
0
3.4k
AI時代の脳疲弊と向き合う ~言語学としてのPHP~
sakuraikotone
1
1.6k
AI 開発合宿を通して得た学び
niftycorp
PRO
0
180
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
800
Smarter Angular mit Transformers.js & Prompt API
christianliebel
PRO
1
100
[PHPerKaigi 2026]PHPerKaigi2025の企画CodeGolfが最高すぎて社内で内製して半年運営して得た内製と運営の知見
ikezoemakoto
0
310
最初からAWS CDKで技術検証してもいいんじゃない?
akihisaikeda
4
180
AIと共にエンジニアとPMの “二刀流”を実現する
naruogram
0
110
年間50登壇、単著出版、雑誌寄稿、Podcast出演、YouTube、CM、カンファレンス主催……全部やってみたので面白さ等を比較してみよう / I’ve tried them all, so let’s compare how interesting they are.
nrslib
3
250
Reactive ❤️ Loom: A Forbidden Love Story
franz1981
2
200
Featured
See All Featured
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
100
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
SEO for Brand Visibility & Recognition
aleyda
0
4.4k
How to Think Like a Performance Engineer
csswizardry
28
2.5k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
330
The Language of Interfaces
destraynor
162
26k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
300
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
1.9k
Thoughts on Productivity
jonyablonski
75
5.1k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Transcript
2024/09/05 omotesando.rb #101 株式会社タイミー 新谷哲平 いつか使えるObjectSpace @euglena1215
自己紹介 Shintani Teppei(@euglena1215) • 株式会社タイミー • バックエンド テックリード • 最近は
Ruby よりも日本語を 書いています
最初に質問 ObjectSpace 知ってる方
こんな方向け • ObjectSpace 知らない・触ったことない → これまでできなかったことができるようになるかも?
ObjectSpaceってなに? ObjectSpace は Ruby の組み込みライブラリ https://docs.ruby-lang.org/ja/latest/class/ObjectSpace.html
ObjectSpaceってなに? ObjectSpace は Ruby の組み込みライブラリ https://docs.ruby-lang.org/ja/latest/class/ObjectSpace.html
ObjectSpaceってなに? ObjectSpace は Ruby の組み込みライブラリ https://docs.ruby-lang.org/ja/latest/class/ObjectSpace.html 🧙🔮🧙
ObjectSpaceってなに? 今回は ObjectSpace モジュールに定義されているメソッド3つを紹介 • ObjectSpace._id2ref • ObjectSpace.count_objects • ObjectSpace.each_object
ObjectSpace._id2ref
ObjectSpace._id2ref オブジェクトIDからオブジェクトを取得する
ObjectSpace._id2ref Q. どんなときに使える?
ObjectSpace._id2ref Q. どんなときに使える? A. Rails 6より前の ActiveSupport Instrumentation API の
sql.active_record では connection_id を受け取っていた。id から connection を取得するために必要。
ObjectSpace._id2ref Q. どんなときに使える? A. Rails 6より前の ActiveSupport Instrumentation API の
sql.active_record では connection_id を受け取っていた。id から connection を取得するために必要。 おそらく現代において使うことはほとんどないのでは...?
ObjectSpace.count_objects
ObjectSpace.count_objects オブジェクトの種類ごとに現時点で生成されている個数を返す
ObjectSpace.count_objects 例:blockとして渡した処理で生成されたHashオブジェクトの個数を返すメソッド
ObjectSpace.count_objects 例:blockとして渡した処理で生成されたHashオブジェクトの個数を返すメソッド
ObjectSpace.count_objects Q. どんなときに使える?
ObjectSpace.count_objects Q. どんなときに使える? A. メモリを意識したコードを書きたくなったとき...?
ObjectSpace.count_objects Q. どんなときに使える? A. メモリを意識したコードを書きたくなったとき...? Model.where(...).map(&:user_id) と Model.where(...).pluck(:user_id) の 生成オブジェクト数の違いを見てみると面白いかも
ObjectSpace.each_object
ObjectSpace.each_object 全てのオブジェクトもしくは任意のクラスのオブジェクトに繰り返し処理を行う
メタプログラミング Ruby の時間です クラスは全て Class クラスのインスタンス(オブジェクト)
メタプログラミング Ruby の時間です クラスは全て Class クラスのインスタンス(オブジェクト) ObjectSpace.each_object(Class) を実行すると...
メタプログラミング Ruby の時間です クラスは全て Class クラスのインスタンス(オブジェクト) ObjectSpace.each_object(Class) を実行すると... 定義されている全クラスの一覧を取得できる 🔮
ObjectSpace.each_object 全クラスの一覧が取得できるなら、特定クラスを継承したクラス一覧も取得できる ApplicationRecord を継承したクラスの一覧、ApplicationJob を継承したクラスの 一覧とか出せると便利なことがたまにある
ObjectSpace知ってると便利なことが稀にある 良い Ruby プログラミングライフを!