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
290
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
いつか使える 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
150
「地続き」の技術面接 / "Continuous" technical interview
euglena1215
0
83
allow_retry と Arel.sql / allow_retry and Arel.sql
euglena1215
1
320
AIと”コードの評価関数”を共有する / Share the "code evaluation function" with AI
euglena1215
1
290
ISUCONで型をつける
euglena1215
1
170
3年でバックエンドエンジニアが5倍に増えても破綻しなかったアーキテクチャ そして、これから / Software architecture that scales even with a 5x increase in backend engineers in 3 years
euglena1215
11
5.8k
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
8
1.2k
rbs-inlineを導入してYARDからRBSに移行する
euglena1215
1
1k
Ruby の型に関する活動をやっている話 / Activities related to Ruby types
euglena1215
3
460
Other Decks in Programming
See All in Programming
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
530
FDEが実現するAI駆動経営の現在地
gonta
2
220
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
2.1k
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
180
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
140
AIが無かった頃の素敵な出会いの話
codmoninc
1
220
AIエージェントで 変わるAndroid開発環境
takahirom
2
720
1年で人数1.5倍、PR数5.5倍増。 品質とアウトカムはどうなったか、 何が効いたか
ike002jp
0
150
共通化で考えるべきは、実装より公開する型だった
codeegg
0
280
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
240
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
3k
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
440
Featured
See All Featured
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
180
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
270
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
450
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Marketing to machines
jonoalderson
1
5.6k
Prompt Engineering for Job Search
mfonobong
0
380
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
620
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
280
The Invisible Side of Design
smashingmag
301
52k
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 プログラミングライフを!