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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Shintani Teppei
September 05, 2024
Programming
270
2
Share
いつか使える ObjectSpace / Maybe useful ObjectSpace
Omotesando.rb#101 の発表資料です。
https://omotesandorb.connpass.com/event/328438/
Shintani Teppei
September 05, 2024
More Decks by Shintani Teppei
See All by Shintani Teppei
すべてがオンボーディングタスクになる / Everything becomes an onboarding task
euglena1215
0
100
「地続き」の技術面接 / "Continuous" technical interview
euglena1215
0
55
allow_retry と Arel.sql / allow_retry and Arel.sql
euglena1215
1
290
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.7k
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
8
1.1k
rbs-inlineを導入してYARDからRBSに移行する
euglena1215
1
950
Ruby の型に関する活動をやっている話 / Activities related to Ruby types
euglena1215
3
430
Other Decks in Programming
See All in Programming
ルールルルルルRubyの中身の予備知識 ── RubyKaigiの前に予習しなイカ?
ydah
1
190
ドメインイベントでビジネスロジックを解きほぐす #phpcon_odawara
kajitack
3
790
Offline should be the norm: building local-first apps with CRDTs & Kotlin Multiplatform
renaudmathieu
0
220
UIの境界線をデザインする | React Tokyo #15 メイントーク
sasagar
2
370
tRPCの概要と少しだけパフォーマンス
misoton665
2
220
ハーネスエンジニアリングにどう向き合うか 〜ルールファイルを超えて開発プロセスを設計する〜 / How to approach harness engineering
rkaga
24
14k
Running Swift without an OS
kishikawakatsumi
0
840
Angular Signal Forms
debug_mode
0
110
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
230
AI-DLC Deep Dive
yuukiyo
9
4.4k
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
150
🦞OpenClaw works with AWS
licux
1
140
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
130
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
240
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
190
So, you think you're a good person
axbom
PRO
2
2k
Building Adaptive Systems
keathley
44
3k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
350
Google's AI Overviews - The New Search
badams
0
980
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
Music & Morning Musume
bryan
47
7.2k
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 プログラミングライフを!