The timeless repository


Written by Magnus Holm

require 'open-uri' require 'stringio' # == Feed me with: # # Filename:: and I'll give you the file! # URL:: and I'll give you the content! # Any string:: and I'll give you a StringIO! # An integer:: and I'll give you the stream for # the given integer file descriptor! # Any IO:: and I'll give you the same IO! # # == Set +type+ to: # # +:auto+:: and I'll figure it all out for you! # +String+:: and you'll get a nice StringIO, no matter what! # def SuperIO(io, type = :auto) return if type == String raise "Unknown type" unless type == :auto case io when IO io when Integer when String if File.exists?(io) elsif ((uri = URI.parse(io)).respond_to?(:open) rescue false) else end else raise "Cannot convert to IO" end end