From: "Abinoam Jr." Date: 2010-12-20T10:01:27+09:00 Subject: Re: Regexp, String, Symbol literals' object_ids Try ruby-1.9.2-head > 5.times { p /thesame/.object_id.to_s + ' ' + /thesame/.object_id.to_s} "21522620 21522400" "21522620 21522400" "21522620 21522400" "21522620 21522400" "21522620 21522400" => 5 ruby-1.9.2-head > 5.times { p 'thesame'.object_id.to_s + ' ' + 'thesame'.object_id.to_s} "21553480 21553400" "21553320 21553240" "21553160 21553080" "21553000 21552920" "21552840 21552760" => 5 ruby-1.9.2-head > What is the logic behind this? On Sun, Dec 19, 2010 at 6:55 PM, Quintus wrote: > Am 19.12.2010 21:07, schrieb Pavel R.: >> Regexp literals: >> 5.times { p /abcdasdf/.object_id } -> same! >> > > How is this possible? For every time the loop is executed there should a > new regexp be created... Have a look at this which seems confusing to me: > > #ruby -v: ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux] > irb(main):001:0> 5.times { p /abcdasdf/.object_id } > 8030280 > 8030280 > 8030280 > 8030280 > 8030280 > => 5 > irb(main):002:0> p /abcdasdf/.object_id > 8049600 > => 8049600 > irb(main):003:0> p /abcdasdf/.object_id > 8063560 > => 8063560 > irb(main):004:0> > > The regexp in the loop always stays the same, but if I create some > others outside the loop, they get a different object ID? Can anybody > shade some light on this? > > Valete, > Marvin > >