On Wed, Aug 20, 2008 at 5:38 PM, <brabuhr / gmail.com> wrote: >> <ruby-forum.com / nick-brown.com> wrote: >>> "puts #{a}" outputs the modified version of a, but inserting that *exact >>> same* string object into a database puts an UNMODIFIED version of the >>> string into the DB. It's as if db.execute looks back in time to before >>> the sub! when it gets the value of a. Something unexplained is going on >>> here (unless the database module includes a time machine). > > irb(main)> cgi = CGI.new('html4') > (offline mode: enter name=value pairs on standard input) > a=hi > => #<CGI:0xb7c367b8 @params={"a"=>["hi"]}, @multipart=false, > @output_cookies=nil, @output_hidden=nil, @cookies={}> > > irb(main)> a = cgi['a'] > => "hi" > > irb(main)> a.sub!(/hi/, 'bye') > => "bye" > > irb(main)> a > => "bye" > > irb(main)> [a] > => ["bye"] > > irb(main)> [a].flatten > => ["hi"] irb(main):061:0> b = "hi" => "hi" irb(main):062:0> b.sub!(/hi/, 'bye') => "bye" irb(main):063:0> [b] => ["bye"] irb(main):064:0> [b].flatten => ["bye"]