Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chomp to IO#readline and IO#readlines #2059

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/io.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ class IO < Object
# Optional keyword argument `chomp` specifies whether line separators are to be
# omitted.
#
def readline: (?String sep, ?Integer limit) -> String
def readline: (?String sep, ?Integer limit, ?chomp: boolish) -> String

# <!--
# rdoc-file=io.c
Expand Down Expand Up @@ -1701,7 +1701,7 @@ class IO < Object
# # => ["First line", "Second line", "", "Fourth line", "Fifth line"]
# f.close
#
def readlines: (?String sep, ?Integer limit) -> ::Array[String]
def readlines: (?String sep, ?Integer limit, ?chomp: boolish) -> ::Array[String]

# <!--
# rdoc-file=io.c
Expand Down
32 changes: 32 additions & 0 deletions test/stdlib/IO_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,38 @@ def test_gets
io, :gets, nil, chomp: true
end
end

def test_readlines
IO.open(IO.sysopen(File.expand_path(__FILE__))) do |io|
assert_send_type '() -> Array[String]',
io, :readlines

assert_send_type '(String, Integer) -> Array[String]',
io, :readlines, "\n", 100

assert_send_type '(chomp: bool) -> Array[String]',
io, :readlines, chomp: true

assert_send_type '(String, Integer, chomp: bool) -> Array[String]',
io, :readlines, "\n", 100, chomp: true
end
end

def test_readline
IO.open(IO.sysopen(File.expand_path(__FILE__))) do |io|
assert_send_type '() -> String',
io, :readline

assert_send_type '(String, Integer) -> String',
io, :readline, "\n", 100

assert_send_type '(chomp: bool) -> String',
io, :readline, chomp: true

assert_send_type '(String, Integer, chomp: bool) -> String',
io, :readline, "\n", 100, chomp: true
end
end
end

class IOWaitTest < Test::Unit::TestCase
Expand Down