Tim Wolak wrote: > I'm not sure if I'm using this the right way and I'm hoping you guys can > help. > > I am merging two hashes together using merge and need to keep the keys > the same and subtract the difference between the two values. The keys > are account numbers and the values are the balances. Not sure why the > balances are not subtracting and creating the new value. > > Thanks in advance. > Tim > > class Calculate > attr_reader :sktyfuta, :sktyfutb > def initialize(sktyfuta, sktyfutb) > @sktyfuta = sktyfuta > @sktyfutb = sktyfutb > end > > def data_comp > @sktyfuta.merge(@sktyfutb) { |key, old_value, new_value| old_value > - new_value } > end > end Hash.merge will give you a new Hash, a third one. If somewhere outside of your class you call the method data_comp, it will return this new Hash. a = some_instance_of Calculate.datacomp p a I guess you expect @sktyfuta to change, but it won't unless you tell it to. Regards, Siep -- Posted via http://www.ruby-forum.com/.