Skip to content

Instantly share code, notes, and snippets.

@evizitei
Created July 2, 2010 18:32
Show Gist options
  • Save evizitei/461709 to your computer and use it in GitHub Desktop.
Save evizitei/461709 to your computer and use it in GitHub Desktop.
def restore_from_destroyed_string(string,clss)
clean_string = string.gsub(/>, #<[A-Za-z0-9]+\sid:/,'}, {:id=>').
gsub(/,\s([A-Za-z0-9_]+):\s/,', :\1=> ').
gsub(/>\]$/,"}]").
gsub(/^\[#<[A-Za-z0-9]+\sid:/,"[{:id=>")
attr_array = eval(clean_string)
attr_array.each do |attrs|
success = clss.new(attrs).save
puts "creating object #{attrs[:id]}...#{success}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment