Skip to content

Commit

Permalink
Refactor logic to be closer to CRuby's logic for IO.copy_stream
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Oct 2, 2023
1 parent 3dd18a6 commit 60b4cfd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/ruby/truffleruby/core/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,16 @@ def initialize(from, to, length, offset)
# From copy_stream_body in io.c in CRuby
# The first element is true if obj can be used as an IO directly
def to_io(obj, mode)
has_to_path = obj.respond_to? :to_path
io = (Primitive.is_a?(obj, IO) || has_to_path) && IO.try_convert(obj)
if io
unless Primitive.is_a?(obj, IO) || Primitive.is_a?(obj, String) || obj.respond_to?(:to_path)
return [false, obj]
end

if io = IO.try_convert(obj)
[true, io]
elsif Primitive.is_a?(obj, String) or has_to_path
else
path = Truffle::Type.coerce_to obj, String, :to_path
io = File.open path, mode
[false, io]
else
[false, obj]
end
end

Expand Down

0 comments on commit 60b4cfd

Please sign in to comment.