The Ruby regex /o modifier causes interpolated expressions to be evaluated only once and cached permanently at the VM level, creating unexpected behavior where the first interpolated value becomes fixed for all subsequent uses. This can lead to confusing bugs where regex patterns appear to work correctly in isolation but fail when used in classes or across multiple instances. The modifier uses Ruby's 'once' VM instruction for caching, making it thread-safe but non-deterministic in multi-threaded environments. Despite potential performance benefits, the /o modifier is considered dangerous and should be avoided in favor of explicit regex caching.

18m read timeFrom jpcamara.com
Post cover image
Table of contents
The cliffs of insanity/o the humanity!Inside the VMonce upon a timeWhy does it exist?I’ll take your once , and raise you…The inmates are running the asylumThis is the END

Sort: