Skip to content

Commit 1744e33

Browse files
nobuhsbt
authored andcommitted
Forward keyword arguments for Pathname#each_line [Bug #17589]
1 parent 19cb878 commit 1744e33

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

ext/pathname/pathname.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,10 @@ path_each_line(int argc, VALUE *argv, VALUE self)
360360
args[0] = get_strpath(self);
361361
n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
362362
if (rb_block_given_p()) {
363-
return rb_block_call(rb_cFile, id_foreach, 1+n, args, 0, 0);
363+
return rb_block_call_kw(rb_cFile, id_foreach, 1+n, args, 0, 0, RB_PASS_CALLED_KEYWORDS);
364364
}
365365
else {
366-
return rb_funcallv(rb_cFile, id_foreach, 1+n, args);
366+
return rb_funcallv_kw(rb_cFile, id_foreach, 1+n, args, RB_PASS_CALLED_KEYWORDS);
367367
}
368368
}
369369

test/pathname/test_pathname.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,32 @@ def test_each_line
707707
}
708708
end
709709

710+
def test_each_line_opts
711+
with_tmpchdir('rubytest-pathname') {|dir|
712+
open("a", "w") {|f| f.puts 1, 2 }
713+
a = []
714+
Pathname("a").each_line(chomp: true) {|line| a << line }
715+
assert_equal(["1", "2"], a)
716+
717+
a = []
718+
Pathname("a").each_line("2", chomp: true) {|line| a << line }
719+
assert_equal(["1\n", "\n"], a)
720+
721+
a = []
722+
Pathname("a").each_line(1, chomp: true) {|line| a << line }
723+
assert_equal(["1", "", "2", ""], a)
724+
725+
a = []
726+
Pathname("a").each_line("2", 1, chomp: true) {|line| a << line }
727+
assert_equal(["1", "\n", "", "\n"], a)
728+
729+
a = []
730+
enum = Pathname("a").each_line(chomp: true)
731+
enum.each {|line| a << line }
732+
assert_equal(["1", "2"], a)
733+
}
734+
end
735+
710736
def test_readlines
711737
with_tmpchdir('rubytest-pathname') {|dir|
712738
open("a", "w") {|f| f.puts 1, 2 }

0 commit comments

Comments
 (0)