1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Forward keyword arguments for Pathname#each_line [Bug #17589]

This commit is contained in:
Nobuyoshi Nakada 2021-01-29 13:09:38 +09:00
parent acb6b395b6
commit 9241211538
Notes: git 2021-01-29 14:28:24 +09:00
2 changed files with 28 additions and 2 deletions

View file

@ -360,10 +360,10 @@ path_each_line(int argc, VALUE *argv, VALUE self)
args[0] = get_strpath(self);
n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
if (rb_block_given_p()) {
return rb_block_call(rb_cFile, id_foreach, 1+n, args, 0, 0);
return rb_block_call_kw(rb_cFile, id_foreach, 1+n, args, 0, 0, RB_PASS_CALLED_KEYWORDS);
}
else {
return rb_funcallv(rb_cFile, id_foreach, 1+n, args);
return rb_funcallv_kw(rb_cFile, id_foreach, 1+n, args, RB_PASS_CALLED_KEYWORDS);
}
}

View file

@ -707,6 +707,32 @@ class TestPathname < Test::Unit::TestCase
}
end
def test_each_line_opts
with_tmpchdir('rubytest-pathname') {|dir|
open("a", "w") {|f| f.puts 1, 2 }
a = []
Pathname("a").each_line(chomp: true) {|line| a << line }
assert_equal(["1", "2"], a)
a = []
Pathname("a").each_line("2", chomp: true) {|line| a << line }
assert_equal(["1\n", "\n"], a)
a = []
Pathname("a").each_line(1, chomp: true) {|line| a << line }
assert_equal(["1", "", "2", ""], a)
a = []
Pathname("a").each_line("2", 1, chomp: true) {|line| a << line }
assert_equal(["1", "\n", "", "\n"], a)
a = []
enum = Pathname("a").each_line(chomp: true)
enum.each {|line| a << line }
assert_equal(["1", "2"], a)
}
end
def test_readlines
with_tmpchdir('rubytest-pathname') {|dir|
open("a", "w") {|f| f.puts 1, 2 }