class ActiveFedora::Base

def update_indexed_attributes(params={}, opts={})


m.update_attributes({"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}, :datastreams=>["my_ds", "my_other_ds"])
or
m.update_attributes({"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}, :datastreams=>"my_ds")
use the :datastreams argument like so:
If you want to specify which datastream(s) to update,

As in update_attributes, this overwrites _all_ available fields by default.

will be overwritten.
An index of -1 will insert a new value. any existing value at the relevant index

This will result in any datastream field of name :name having the value [a,b]

{{:name=>{"0"=>"a","1"=>"b"}}
must look like this :
A convenience method for updating indexed attributes. The passed in hash
def update_indexed_attributes(params={}, opts={})
  if opts[:datastreams]
    ds_array = []
    opts[:datastreams].each do |dsname|
      ds_array << datastreams[dsname]
    end
  else
    ds_array = datastreams.values
  end
  result = params.dup
  params.each do |key,value|
    result[key] = value.dup
    ds_array.each do |dstream|
      if dstream.fields[key.to_sym]
        aname="#{key}_values"
        curval = dstream.send("#{aname}")
        cpv=value.dup#copy this, we'll need the original for the next ds
        cpv.delete_if do |y,z| 
          if curval[y.to_i] and y.to_i > -1
            curval[y.to_i]=z
            true
          else
            false
          end
        end 
        cpv.each do |y,z| 
          curval<<z #just append everything left
          if y == "-1"
            new_array_index = curval.length - 1
            result[key][new_array_index.to_s] = params[key]["-1"]
          end
        end
        curval.delete_if {|x| x == :delete || x == "" || x == nil}
        dstream.send("#{aname}=", curval) #write it back to the ds
      end
    end
    result[key].delete("-1")
  end
  return result
end