#--
###############################################################################
#                                                                             #
# nuggets -- Extending Ruby                                                   #
#                                                                             #
# Copyright (C) 2007-2011 Jens Wille                                          #
#                                                                             #
# Authors:                                                                    #
#     Jens Wille <jens.wille@gmail.com>                                       #
#                                                                             #
# nuggets is free software; you can redistribute it and/or modify it under    #
# the terms of the GNU Affero General Public License as published by the Free #
# Software Foundation; either version 3 of the License, or (at your option)   #
# any later version.                                                          #
#                                                                             #
# nuggets is distributed in the hope that it will be useful, but WITHOUT ANY  #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS   #
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for     #
# more details.                                                               #
#                                                                             #
# You should have received a copy of the GNU Affero General Public License    #
# along with nuggets. If not, see <http://www.gnu.org/licenses/>.             #
#                                                                             #
###############################################################################
#++

require 'nuggets/enumerable/agrep'

class IO

  # call-seq:
  #   IO.agrep(fd, pattern[, distance]) -> anArray
  #   IO.agrep(fd, pattern[, distance]) { |line| ... } -> io
  #
  def self.agrep(fd, pattern, distance = 0, &block)
    open(fd) { |io| io.agrep(pattern, distance, &block) }
  end

end

if $0 == __FILE__
  puts ::File.agrep(__FILE__, /calls/, 2)
end
