Skip to content

Commit 6dc879f

Browse files
BurdetteLamarmatzbot
authored andcommitted
[ruby/stringio] [DOC] Tweaks for StringIO.new
(ruby/stringio#144) ruby/stringio@d33ac815c1
1 parent add78e7 commit 6dc879f

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

ext/stringio/stringio.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,32 @@ strio_s_allocate(VALUE klass)
225225
* call-seq:
226226
* StringIO.new(string = '', mode = 'r+') -> new_stringio
227227
*
228-
* Note that +mode+ defaults to <tt>'r'</tt> if +string+ is frozen.
229-
*
230228
* Returns a new \StringIO instance formed from +string+ and +mode+;
231-
* see {Access Modes}[rdoc-ref:File@Access+Modes]:
229+
* the instance should be closed when no longer needed:
232230
*
233-
* strio = StringIO.new # => #<StringIO>
231+
* strio = StringIO.new
232+
* strio.string # => ""
233+
* strio.closed_read? # => false
234+
* strio.closed_write? # => false
234235
* strio.close
235236
*
236-
* The instance should be closed when no longer needed.
237+
* If +string+ is frozen, the default +mode+ is <tt>'r'</tt>:
238+
*
239+
* strio = StringIO.new('foo'.freeze)
240+
* strio.string # => "foo"
241+
* strio.closed_read? # => false
242+
* strio.closed_write? # => true
243+
* strio.close
244+
*
245+
* Argument +mode+ must be a valid
246+
* {Access Mode}[rdoc-ref:File@Access+Modes],
247+
* which may be a string or an integer constant:
248+
*
249+
* StringIO.new('foo', 'w+')
250+
* StringIO.new('foo', File::RDONLY)
237251
*
238-
* Related: StringIO.open (accepts block; closes automatically).
252+
* Related: StringIO.open
253+
* (passes the \StringIO object to the block; closes the object automatically on block exit).
239254
*/
240255
static VALUE
241256
strio_initialize(int argc, VALUE *argv, VALUE self)
@@ -712,7 +727,7 @@ strio_set_lineno(VALUE self, VALUE lineno)
712727
* binmode -> self
713728
*
714729
* Sets the data mode in +self+ to binary mode;
715-
* see {Data Mode}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Data+Mode].
730+
* see {Data Mode}[rdoc-ref:File@Data+Mode].
716731
*
717732
*/
718733
static VALUE

0 commit comments

Comments
 (0)