Skip to content

Commit 60b4cfd

Browse files
committed
Refactor logic to be closer to CRuby's logic for IO.copy_stream
1 parent 3dd18a6 commit 60b4cfd

File tree

1 file changed

+6
-6
lines changed
  • src/main/ruby/truffleruby/core

1 file changed

+6
-6
lines changed

src/main/ruby/truffleruby/core/io.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,16 @@ def initialize(from, to, length, offset)
359359
# From copy_stream_body in io.c in CRuby
360360
# The first element is true if obj can be used as an IO directly
361361
def to_io(obj, mode)
362-
has_to_path = obj.respond_to? :to_path
363-
io = (Primitive.is_a?(obj, IO) || has_to_path) && IO.try_convert(obj)
364-
if io
362+
unless Primitive.is_a?(obj, IO) || Primitive.is_a?(obj, String) || obj.respond_to?(:to_path)
363+
return [false, obj]
364+
end
365+
366+
if io = IO.try_convert(obj)
365367
[true, io]
366-
elsif Primitive.is_a?(obj, String) or has_to_path
368+
else
367369
path = Truffle::Type.coerce_to obj, String, :to_path
368370
io = File.open path, mode
369371
[false, io]
370-
else
371-
[false, obj]
372372
end
373373
end
374374

0 commit comments

Comments
 (0)