
Issue #19439 has been updated by byroot (Jean Boussier). After a quick check, it's because the IVAR on Regexps is used to store the encoding: ```c case TYPE_REGEXP: { VALUE str = r_bytes(arg); int options = r_byte(arg); int has_encoding = FALSE; st_index_t idx = r_prepare(arg); if (ivp) { r_ivar(str, &has_encoding, arg); *ivp = FALSE; } ``` I'll dig a bit more, but it may be a fundamental limitation of the format. ---------------------------------------- Bug #19439: Marshal.load doesn't load Regexp instance variables https://bugs.ruby-lang.org/issues/19439#change-101890 * Author: andrykonchin (Andrew Konchin) * Status: Open * Priority: Normal * ruby -v: 3.1.3 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Hello, I've noticed this strange behaviour: ```ruby source_object = Regexp.new("a") source_object.instance_variable_set(:@foo, :bar) regexp = Marshal.load(Marshal.dump(source_object)) regexp.instance_variables # => [] ``` I would expect instance variables to be loaded -- https://bugs.ruby-lang.org/