Project

General

Profile

Feature #3608 ยป lazy_each_child.diff

taw (Tomasz Wegrzanowski), 07/24/2010 10:27 AM

View differences:

ext/pathname/lib/pathname.rb (working copy)
655 655
  # This method has existed since 1.8.1.
656 656
  #
657 657
  def children(with_directory=true)
658
    with_directory = false if @path == '.'
659
    result = []
660
    Dir.foreach(@path) {|e|
661
      next if e == '.' || e == '..'
662
      if with_directory
663
        result << self.class.new(File.join(@path, e))
664
      else
665
        result << self.class.new(e)
666
      end
667
    }
668
    result
658
    each_child(with_directory).to_a
669 659
  end
670 660

  
671 661
  # Iterates over the children of the directory
......
694 684
  #   #   #<Pathname:src>
695 685
  #   #   #<Pathname:man>
696 686
  #
697
  def each_child(with_directory=true, &b)
698
    children(with_directory).each(&b)
687
  def each_child(with_directory=true)
688
    block_given? or return enum_for(__method__, with_directory)
689
    with_directory = false if @path == '.'
690
    Dir.foreach(@path) {|e|
691
      next if e == '.' || e == '..'
692
      if with_directory
693
        yield self.class.new(File.join(@path, e))
694
      else
695
        yield self.class.new(e)
696
      end
697
    }
699 698
  end
700 699

  
701 700
  #