class REXML::SourceFactory - rexml: Ruby Standard Library Documentation

# class REXML::SourceFactory

Generates Source-s. USE THIS CLASS.

### Public Class Methods

create_from(arg) click to toggle source

Generates a `Source` object @param arg Either a String, or an IO @return a `Source`, or nil if a bad argument was given

    # File rexml-3.4.0/lib/rexml/source.rb, line 42
    def SourceFactory::create_from(arg)
      if arg.respond_to? :read and
          arg.respond_to? :readline and
          arg.respond_to? :nil? and
          arg.respond_to? :eof?
        IOSource.new(arg)
      elsif arg.respond_to? :to_str
        IOSource.new(StringIO.new(arg))
      elsif arg.kind_of? Source
        arg
      else
        raise "#{arg.class} is not a valid input stream.  It must walk \n"+
          "like either a String, an IO, or a Source."
      end
    end