From 67e1a2188b9ceb15c6c76001797e56aeb354e00a Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Thu, 28 Dec 2017 02:51:47 -0300 Subject: [PATCH] Fix missing Dir#each to be an Enumerable (#5458) --- spec/std/dir_spec.cr | 6 +++--- src/dir.cr | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/std/dir_spec.cr b/spec/std/dir_spec.cr index 3e3bd776a9dd..ad2f50c26525 100644 --- a/spec/std/dir_spec.cr +++ b/spec/std/dir_spec.cr @@ -234,7 +234,7 @@ describe "Dir" do filenames = [] of String dir = Dir.new(__DIR__) - dir.each_entry do |filename| + dir.each do |filename| filenames << filename end.should be_nil dir.close @@ -246,7 +246,7 @@ describe "Dir" do filenames = [] of String Dir.open(__DIR__) do |dir| - dir.each_entry do |filename| + dir.each do |filename| filenames << filename end.should be_nil end @@ -272,7 +272,7 @@ describe "Dir" do it "gets dir iterator" do filenames = [] of String - iter = Dir.new(__DIR__).each_entry + iter = Dir.new(__DIR__).each iter.each do |filename| filenames << filename end diff --git a/src/dir.cr b/src/dir.cr index ebc66e6c8eb8..22c41e510cd5 100644 --- a/src/dir.cr +++ b/src/dir.cr @@ -43,7 +43,7 @@ class Dir # File.write("testdir/config.h", "") # # d = Dir.new("testdir") - # d.each_entry { |x| puts "Got #{x}" } + # d.each { |x| puts "Got #{x}" } # ``` # # produces: @@ -53,20 +53,20 @@ class Dir # Got .. # Got config.h # ``` - def each_entry : Nil + def each : Nil while entry = read yield entry end end - def each_entry + def each EntryIterator.new(self) end # Returns an array containing all of the filenames in the given directory. def entries : Array(String) entries = [] of String - each_entry do |filename| + each do |filename| entries << filename end entries @@ -80,7 +80,7 @@ class Dir # File.write("testdir/config.h", "") # # d = Dir.new("testdir") - # d.each_entry { |x| puts "Got #{x}" } + # d.each_child { |x| puts "Got #{x}" } # ``` # # produces: @@ -159,10 +159,10 @@ class Dir end end - # See `#each_entry`. - def self.each_entry(dirname) + # See `#each`. + def self.each(dirname) Dir.open(dirname) do |dir| - dir.each_entry do |filename| + dir.each do |filename| yield filename end end