Skip to content

Commit

Permalink
[GR-20446] Update IO#write to accept multiple arguments
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/2981
  • Loading branch information
bjfish committed Oct 21, 2021
2 parents 8090387 + 1f66122 commit 37c7070
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Compatibility:
* Add `Thread.ignore_deadlock` accessor (#2453).
* Allow `Hash#transform_keys` to take a hash argument (@ccocchi, #2464).
* Add `Enumerable#grep{_v}` optimization for `Regexp` (#2453).
* Update `IO#write` to accept multiple arguments (#2501).

Performance:

Expand Down
1 change: 0 additions & 1 deletion spec/tags/core/io/write_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
slow:IO.write on a FIFO writes correctly
fails:IO#write accepts multiple arguments
8 changes: 6 additions & 2 deletions src/main/ruby/truffleruby/core/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2375,8 +2375,12 @@ def ungetc(obj)
nil
end

def write(data)
data = String data
def write(*data)
data = if data.size > 1
data.map { |d| Truffle::Type.rb_obj_as_string(d) }.join
else
Truffle::Type.rb_obj_as_string(data[0])
end
return 0 if data.empty?

ensure_open_and_writable
Expand Down

0 comments on commit 37c7070

Please sign in to comment.