ruby-changes:49904
From: nobu <ko1@a...>
Date: Wed, 24 Jan 2018 16:16:00 +0900 (JST)
Subject: [ruby-changes:49904] nobu:r62022 (trunk): dir.c: Dir#each_child
nobu 2018-01-24 16:15:55 +0900 (Wed, 24 Jan 2018) New Revision: 62022 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62022 Log: dir.c: Dir#each_child * dir.c (dir_each_child_m): new instance methods Dir#each_child and Dir#children. [Feature #13969] Modified files: trunk/NEWS trunk/dir.c trunk/test/ruby/test_dir.rb Index: dir.c =================================================================== --- dir.c (revision 62021) +++ dir.c (revision 62022) @@ -2860,6 +2860,13 @@ dir_s_each_child(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/dir.c#L2860 } static VALUE +dir_each_child_m(VALUE dir) +{ + RETURN_ENUMERATOR(dir, 0, 0); + return dir_each_entry(dir, dir_yield, Qnil, TRUE); +} + +static VALUE dir_collect_children(VALUE dir) { VALUE ary = rb_ary_new(); @@ -3212,6 +3219,8 @@ Init_Dir(void) https://github.com/ruby/ruby/blob/trunk/dir.c#L3219 rb_define_method(rb_cDir,"inspect", dir_inspect, 0); rb_define_method(rb_cDir,"read", dir_read, 0); rb_define_method(rb_cDir,"each", dir_each, 0); + rb_define_method(rb_cDir,"each_child", dir_each_child_m, 0); + rb_define_method(rb_cDir,"children", dir_collect_children, 0); rb_define_method(rb_cDir,"rewind", dir_rewind, 0); rb_define_method(rb_cDir,"tell", dir_tell, 0); rb_define_method(rb_cDir,"seek", dir_seek, 1); Index: NEWS =================================================================== --- NEWS (revision 62021) +++ NEWS (revision 62022) @@ -20,6 +20,12 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L20 === Core classes updates (outstanding ones only) +* Dir + + * New methods: + + * added Dir#each_child and Dir#children instance methods. [Feature #13969] + * Proc * Proc#call doesn't change $SAFE any more. [Feature #14250] Index: test/ruby/test_dir.rb =================================================================== --- test/ruby/test_dir.rb (revision 62021) +++ test/ruby/test_dir.rb (revision 62022) @@ -232,14 +232,17 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L232 end def test_foreach + assert_entries(Dir.open(@root) {|dir| dir.each.to_a}) assert_entries(Dir.foreach(@root).to_a) end def test_children + assert_entries(Dir.open(@root) {|dir| dir.children}, true) assert_entries(Dir.children(@root), true) end def test_each_child + assert_entries(Dir.open(@root) {|dir| dir.each_child.to_a}, true) assert_entries(Dir.each_child(@root).to_a, true) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/