PathnameでFindするには

FindモジュールでもPathnameを扱えたらいいのにと思って以下のコードを書いた後、

require 'find'

module Find
  require 'pathname'

  def find_with_path(*paths)
    find(*paths) do |file|
      yield(Pathname(file))
    end
  end
  module_function :find_with_path
end

Find.find_with_path('.') do |path|
  Find.prune if path.basename == Pathname('some_dir')
  p path
end

ふとPathnameのマニュアルを読むと、Pathname#find(&block)なんてメソッドが用意されていました。おー、こっちを使うべきなのか。なるほど、納得です。

require 'pathname'

Pathname('.').find do |path|
  Find.prune if path.basename == Pathname('some_dir')
  p path
end