# File lib/backports/tools/path.rb, line 6
  def self.convert_first_argument_to_path(klass, selector)
    mod = class << klass; self; end
    unless mod.method_defined? selector
      warn "#{mod}##{selector} is not defined, so argument can't converted to path"
      return
    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_path(file)\n\#{aliased_target}_without_potential_path_argument\#{punctuation}(\#{arg_sequence})\nend\n", __FILE__, __LINE__ + 1
    end
  end