Overriding initialize without causing infinite loop

I think you might want to change your approach a little. Even if there was no infinite loop, calling Image.new in your initialize method would not cause your variable ‘upload’ to have and Image in it, it would still just have an Upload in it. You might want to try something like this…

class Upload
def self.create_from( attributes )
case attributes[:file].content_type
when /^image/
Image.new( attributes )
#…
else
Upload.new( attributes )

end

end
end

class Image < Upload; end

upload = Upload.create_from( params[:upload] )

Mark