How can I get the outer_loop of multiple faces?

require 'set'

module Example

  # @return [Array<Sketchup::Edge>]
  def self.entity_set_border(entities)
    # Collect all faces in selection set for fast lookup.
    selection_faces = Set.new(entities.grep(Sketchup::Face))

    # Collect all edges for the faces in the selection set for fast lookup.
    edges = Set.new
    selection_faces.each { |face| edges.merge(face.edges) }

    # Find the edges that connects to only one of the faces in the selection.
    border = edges.select { |edge|
      num_faces = edge.faces.count { |face| selection_faces.include?(face) }
      num_faces == 1
    }

    border
  end

  # Example.select_selection_border
  def self.select_selection_border
    model = Sketchup.active_model
    border = self.entity_set_border(model.selection)
    model.selection.clear
    model.selection.add(border)
    nil
  end

end # module