Bugs item #10538, was opened at 2007-05-03 02:17 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=1698&aid=10538&group_id=426 Category: Core Group: 1.8.5 Status: Open Resolution: None Priority: 3 Submitted By: Carl Graff (cgramona2) Assigned to: Nobody (None) Summary: sub! causing unexpected side effect Initial Comment: I have a section of code that behaves unexpectedly in my opinion. First the section of code: def adjust_bol_row(bol_row, hist_bol_row, change_disp = true) adj_bol_row = bol_row.dup adj_bol_row['DISPOSITION'] = 'ADD' if change_disp adj_bol_row['SHIPMENT_PRI_REF'].sub!(/-..-/,hist_bol_row['SHIPMENT_PRI_REF'][/-..-/]) if hist_bol_row return adj_bol_row end The statement: adj_bol_row['SHIPMENT_PRI_REF'].sub!(/-..-/,hist_bol_row['SHIPMENT_PRI_REF'][/-..-/]) if hist_bol_row Causes adj_bol_row['SHIPMENT_PRI_REF'] to get updated as expected BUT has the side affect of updating bol_row['SHIPMENT_PRI_REF'] When I use this code def adjust_bol_row(bol_row, hist_bol_row, change_disp = true) adj_bol_row = bol_row.dup adj_bol_row['DISPOSITION'] = 'ADD' if change_disp adj_bol_row['SHIPMENT_PRI_REF'] = adj_bol_row['SHIPMENT_PRI_REF'].sub(/-..-/,hist_bol_row['SHIPMENT_PRI_REF'][/-..-/]) if hist_bol_row return adj_bol_row end Only hash element adj_bol_row['SHIPMENT_PRI_REF'] gets updated as I expect. Why would sub! in this case cause another hash to get updated? Thanks, Carl ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=1698&aid=10538&group_id=426