# File lib/backports/tools.rb, line 121
  def self.convert_first_argument_to_path(mod, *methods)
    methods.each do |selector|
      unless mod.method_defined? selector
        warn "#{mod}##{selector} is not defined, so argument can't converted to path"
        next
      end
      arity = mod.instance_method(selector).arity
      last_arg = []
      if arity < 0
        last_arg = ["*rest"]
        arity = -1-arity
      end
      arg_sequence = (["file"] + (1...arity).map{|i| "arg_#{i}"} + last_arg + ["&block"]).join(", ")

      alias_method_chain(mod, selector, :potential_path_argument) do |aliased_target, punctuation|
        mod.module_eval "def \#{aliased_target}_with_potential_path_argument\#{punctuation}(\#{arg_sequence})\nfile = Backports.convert_to_path(file)\n\#{aliased_target}_without_potential_path_argument\#{punctuation}(\#{arg_sequence})\nend\n"
      end
    end
  end