Project

General

Profile

Actions

Bug #21260

closed

duping stringio objects shares cursors

Added by chucke (Tiago Cardoso) 6 days ago. Updated 5 days ago.

Status:
Feedback
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x86_64-darwin23]
[ruby-core:121608]

Description

I've found that, if I .dup a stringio, when I read one of the objects, the cursor also moves internally on the other:

require "stringio"
s1 = StringIO.new("test")
s2 = s1.dup
s1.read #=> "test"
s2.read #=> ""
s1.rewind
s2.rewind
s2.read #=> "test"
s1.read #=> ""
s1.pos #=> 4
s2.pos #=> 4

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0