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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Shintani Teppei
September 05, 2024
Programming
2
250
いつか使える 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
allow_retry と Arel.sql / allow_retry and Arel.sql
euglena1215
1
240
AIと”コードの評価関数”を共有する / Share the "code evaluation function" with AI
euglena1215
1
250
ISUCONで型をつける
euglena1215
1
140
3年でバックエンドエンジニアが5倍に増えても破綻しなかったアーキテクチャ そして、これから / Software architecture that scales even with a 5x increase in backend engineers in 3 years
euglena1215
11
5.5k
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
8
1.1k
rbs-inlineを導入してYARDからRBSに移行する
euglena1215
1
920
Ruby の型に関する活動をやっている話 / Activities related to Ruby types
euglena1215
3
410
そろそろ理解する includes / Understanding includes
euglena1215
1
990
習うより慣れる Ruby AST / Ruby AST is better to get used to than to learn.
euglena1215
2
740
Other Decks in Programming
See All in Programming
AtCoder Conference 2025
shindannin
0
1.1k
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
230
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
560
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
200
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
730
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
170
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
120
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6.1k
Data-Centric Kaggle
isax1015
2
770
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.2k
Documentation Writing (for coders)
carmenintech
77
5.3k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
160
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
320
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Mobile First: as difficult as doing things right
swwweet
225
10k
KATA
mclloyd
PRO
34
15k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
170
Ruling the World: When Life Gets Gamed
codingconduct
0
140
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
64
Navigating Team Friction
lara
192
16k
Crafting Experiences
bethany
1
48
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 プログラミングライフを!