#
# compat.rb
#

unless Enumerable.method_defined?(:map)
  module Enumerable
    alias map collect
  end
end

unless Enumerable.method_defined?(:select)
  module Enumerable
    alias select find_all
  end
end

unless Enumerable.method_defined?(:reject)
  module Enumerable
    def reject
      result = []
      each do |i|
        result.push i unless yield(i)
      end
      result
    end
  end
end

unless Enumerable.method_defined?(:inject)
  module Enumerable
    def inject(result)
      each do |i|
        result = yield(result, i)
      end
      result
    end
  end
end

unless Enumerable.method_defined?(:any?)
  module Enumerable
    def any?
      each do |i|
        return true if yield(i)
      end
      false
    end
  end
end

unless File.respond_to?(:read)
  def File.read(fname)
    File.open(fname, 'rb') {|f|
      return f.read
    }
  end
end
