seniorRuby

How does Ruby optimize method calls using polymorphic inline caches (PIC)?

Updated May 17, 2026

Short answer

PIC stores multiple class-method mappings at a call site to speed up dynamic dispatch.

Deep explanation

When a method call site sees multiple receiver types, Ruby evolves from monomorphic inline cache (single type fast path) to polymorphic inline cache (multiple cached entries). Each entry maps a receiver class to a resolved method pointer. This avoids full method lookup across inheritance chains.

Unlock with a Pro subscription to view this section.

View pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More Ruby interview questions

View all →