From 3b1eb9a8961977815841b7c9db301057f7aae0bb Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Wed, 22 Oct 2025 00:16:29 +0100 Subject: [PATCH 1/2] [DOC] Tweaks for StringIO.new --- ext/stringio/stringio.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index aaf008ad..daf28315 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -223,19 +223,34 @@ strio_s_allocate(VALUE klass) /* * call-seq: - * StringIO.new(string = '', mode = 'r+') -> new_stringio - * - * Note that +mode+ defaults to 'r' if +string+ is frozen. + * self.new(string = '', mode = 'r+') -> new_stringio * * Returns a new \StringIO instance formed from +string+ and +mode+; - * see {Access Modes}[rdoc-ref:File@Access+Modes]: + * the instance should be closed when no longer needed: + * + * strio = StringIO.new + * strio.string # => "" + * strio.closed_read? # => false + * strio.closed_write? # => false + * strio.close + * + * If +string+ is frozen, the default +mode+ is 'r': * - * strio = StringIO.new # => # + * strio = StringIO.new('foo'.freeze) + * strio.string # => "foo" + * strio.closed_read? # => false + * strio.closed_write? # => true * strio.close * - * The instance should be closed when no longer needed. + * Argument +mode+ must be a valid + * {Access Mode}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes], + * which may be a string or an integer constant: + * + * StringIO.new('foo', 'w+') + * StringIO.new('foo', File::RDONLY) * - * Related: StringIO.open (accepts block; closes automatically). + * Related: StringIO.open + * (passes the \StringIO object to the block; closes the object automatically on block exit). */ static VALUE strio_initialize(int argc, VALUE *argv, VALUE self) From 9aeaade5a6da6e9a7749082734de03c4bd432a45 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Wed, 22 Oct 2025 16:02:56 +0100 Subject: [PATCH 2/2] [DOC] Tweaks for StringIO.new --- ext/stringio/stringio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index daf28315..7b2ec144 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -223,7 +223,7 @@ strio_s_allocate(VALUE klass) /* * call-seq: - * self.new(string = '', mode = 'r+') -> new_stringio + * StringIO.new(string = '', mode = 'r+') -> new_stringio * * Returns a new \StringIO instance formed from +string+ and +mode+; * the instance should be closed when no longer needed: