From: Holden Glova Date: 2002-11-16T07:46:48+09:00 Subject: Re: Regexp: What does //o do? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sat, 16 Nov 2002 10:19, Michael Campbell wrote: > > Yes. It's not completely clear to me when it will be recompiled > > and when it won't be. Above it is not. Below it is. > > > > irb(main):001:0> s="a" > > "a" > > irb(main):002:0> /#{s}/o > > /a/ > > irb(main):003:0> s="b" > > "b" > > irb(main):004:0> /#{s}/o > > /b/ > > This is 2 different regex's, even though they evaluate to the same, > so each one is compiled once. (2 different spots in the source code) > > > irb(main):016:0> def foo(s) > > irb(main):017:1> re = /#{s}/o > > irb(main):018:1> p re > > irb(main):019:1> re = nil > > irb(main):020:1> end > > nil > > irb(main):021:0> foo("a") > > /a/ > > nil > > irb(main):022:0> foo("b") > > /a/ > > nil > > > > and I'm confused even more. > > That's the SAME regex (same spot in the source code) used twice. > Your first example was 2 different regex's, used once each. I'm not sure I can agree that this is the same regex, Jim is setting it to nil at the end of the function so that also is 2 different regex objects. What sort of voodoo is going on here? I too am confused. I didn't know about the /o modifier and I think it is pretty cool, now if it just made sense to me.... :) - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE91Xmd0X8w8X71zPcRAlqHAJ97xDsWBhOU1gEwpLHCJPHIF8fj3QCfWP2T FTdAyYX5ZchcpkGRavRAmM4= =gZCy -----END PGP SIGNATURE-----