-
Notifications
You must be signed in to change notification settings - Fork 30
[DOC] StringIO doc enhancements #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,9 +257,20 @@ strio_s_allocate(VALUE klass) | |
} | ||
|
||
/* | ||
* call-seq: StringIO.new(string=""[, mode]) | ||
* call-seq: | ||
* StringIO.new(string = '', mode = 'r+') -> new_stringio | ||
* | ||
* Note that +mode+ defaults to <tt>'r'</tt> if +string+ is frozen. | ||
* | ||
* Returns a new \StringIO instance formed from +string+ and +mode+; | ||
* see {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes]: | ||
* | ||
* strio = StringIO.new # => #<StringIO> | ||
* strio.close | ||
* | ||
* Creates new StringIO instance from with _string_ and _mode_. | ||
* The instance should be closed when no longer needed. | ||
* | ||
* Related: StringIO.open (accepts block; closes automatically). | ||
*/ | ||
static VALUE | ||
strio_initialize(int argc, VALUE *argv, VALUE self) | ||
|
@@ -392,11 +403,26 @@ strio_finalize(VALUE self) | |
} | ||
|
||
/* | ||
* call-seq: StringIO.open(string=""[, mode]) {|strio| ...} | ||
* call-seq: | ||
* StringIO.open(string = '', mode = 'r+') {|strio| ... } | ||
* | ||
* Note that +mode+ defaults to <tt>'r'</tt> if +string+ is frozen. | ||
* | ||
* Creates a new \StringIO instance formed from +string+ and +mode+; | ||
* see {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes]. | ||
* | ||
* Equivalent to StringIO.new except that when it is called with a block, it | ||
* yields with the new instance and closes it, and returns the result which | ||
* returned from the block. | ||
* With no block, returns the new instance: | ||
* | ||
* strio = StringIO.open # => #<StringIO> | ||
* | ||
* With a block, calls the block with the new instance | ||
* and returns the block's value; | ||
* closes the instance on block exit. | ||
* | ||
* StringIO.open {|strio| p strio } | ||
* # => #<StringIO> | ||
* | ||
* Related: StringIO.new. | ||
*/ | ||
static VALUE | ||
strio_s_open(int argc, VALUE *argv, VALUE klass) | ||
|
@@ -482,9 +508,23 @@ strio_unimpl(int argc, VALUE *argv, VALUE self) | |
} | ||
|
||
/* | ||
* call-seq: strio.string -> string | ||
* call-seq: | ||
* string -> string | ||
* | ||
* Returns underlying string: | ||
* | ||
* StringIO.open('foo') do |strio| | ||
* p strio.string | ||
* strio.string = 'bar' | ||
* p strio.string | ||
* end | ||
* | ||
* Returns underlying String object, the subject of IO. | ||
* Output: | ||
* | ||
* "foo" | ||
* "bar" | ||
* | ||
* Related: StringIO#string= (assigns the underlying string). | ||
*/ | ||
static VALUE | ||
strio_get_string(VALUE self) | ||
|
@@ -494,9 +534,23 @@ strio_get_string(VALUE self) | |
|
||
/* | ||
* call-seq: | ||
* strio.string = string -> string | ||
* string = other_string -> other_string | ||
* | ||
* Assigns the underlying string as +other_string+, and sets position to zero; | ||
* returns +other_string+: | ||
* | ||
* StringIO.open('foo') do |strio| | ||
* p strio.string | ||
* strio.string = 'bar' | ||
* p strio.string | ||
* end | ||
* | ||
* Changes underlying String object, the subject of IO. | ||
* Output: | ||
* | ||
* "foo" | ||
* "bar" | ||
* | ||
* Related: StringIO#string (returns the underlying string). | ||
*/ | ||
static VALUE | ||
strio_set_string(VALUE self, VALUE string) | ||
|
@@ -514,10 +568,13 @@ strio_set_string(VALUE self, VALUE string) | |
|
||
/* | ||
* call-seq: | ||
* strio.close -> nil | ||
* close -> nil | ||
* | ||
* Closes +self+ for both reading and writing. | ||
peterzhu2118 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* Raises IOError if reading or writing is attempted. | ||
* | ||
* Closes a StringIO. The stream is unavailable for any further data | ||
* operations; an +IOError+ is raised if such an attempt is made. | ||
* Related: StringIO#close_read, StringIO#close_write. | ||
*/ | ||
static VALUE | ||
strio_close(VALUE self) | ||
|
@@ -529,10 +586,13 @@ strio_close(VALUE self) | |
|
||
/* | ||
* call-seq: | ||
* strio.close_read -> nil | ||
* close_read -> nil | ||
* | ||
* Closes the read end of a StringIO. Will raise an +IOError+ if the | ||
* receiver is not readable. | ||
* Closes +self+ for reading; closed-write setting remains unchanged. | ||
* | ||
* Raises IOError if reading is attempted. | ||
* | ||
* Related: StringIO#close, StringIO#close_write. | ||
*/ | ||
static VALUE | ||
strio_close_read(VALUE self) | ||
|
@@ -547,10 +607,13 @@ strio_close_read(VALUE self) | |
|
||
/* | ||
* call-seq: | ||
* strio.close_write -> nil | ||
* close_write -> nil | ||
* | ||
* Closes +self+ for writing; closed-read setting remains unchanged. | ||
* | ||
* Raises IOError if writing is attempted. | ||
* | ||
* Closes the write end of a StringIO. Will raise an +IOError+ if the | ||
* receiver is not writeable. | ||
* Related: StringIO#close, StringIO#close_read. | ||
*/ | ||
static VALUE | ||
strio_close_write(VALUE self) | ||
|
@@ -565,9 +628,10 @@ strio_close_write(VALUE self) | |
|
||
/* | ||
* call-seq: | ||
* strio.closed? -> true or false | ||
* closed? -> true or false | ||
* | ||
* Returns +true+ if the stream is completely closed, +false+ otherwise. | ||
* Returns +true+ if +self+ is closed for both reading and writing, | ||
* +false+ otherwise. | ||
*/ | ||
static VALUE | ||
strio_closed(VALUE self) | ||
|
@@ -579,9 +643,9 @@ strio_closed(VALUE self) | |
|
||
/* | ||
* call-seq: | ||
* strio.closed_read? -> true or false | ||
* closed_read? -> true or false | ||
* | ||
* Returns +true+ if the stream is not readable, +false+ otherwise. | ||
* Returns +true+ if +self+ is closed for reading, +false+ otherwise. | ||
*/ | ||
static VALUE | ||
strio_closed_read(VALUE self) | ||
|
@@ -593,9 +657,9 @@ strio_closed_read(VALUE self) | |
|
||
/* | ||
* call-seq: | ||
* strio.closed_write? -> true or false | ||
* closed_write? -> true or false | ||
* | ||
* Returns +true+ if the stream is not writable, +false+ otherwise. | ||
* Returns +true+ if +self+ is closed for writing, +false+ otherwise. | ||
*/ | ||
static VALUE | ||
strio_closed_write(VALUE self) | ||
|
@@ -615,11 +679,14 @@ strio_to_read(VALUE self) | |
|
||
/* | ||
* call-seq: | ||
* strio.eof -> true or false | ||
* strio.eof? -> true or false | ||
* eof? -> true or false | ||
* | ||
* Returns true if the stream is at the end of the data (underlying string). | ||
* The stream must be opened for reading or an +IOError+ will be raised. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this sentence needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added (three places). |
||
* Returns +true+ if positioned at end-of-stream, +false+ otherwise; | ||
* see {Position}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Position]. | ||
* | ||
* Raises IOError if the stream is not opened for reading. | ||
* | ||
* StreamIO#eof is an alias for StreamIO#eof?. | ||
*/ | ||
static VALUE | ||
strio_eof(VALUE self) | ||
|
@@ -1751,24 +1818,16 @@ strio_set_encoding_by_bom(VALUE self) | |
} | ||
|
||
/* | ||
* Pseudo I/O on String object, with interface corresponding to IO. | ||
* \IO streams for strings, with access similar to | ||
* {IO}[https://docs.ruby-lang.org/en/master/IO.html]; | ||
* see {IO Streams}[https://docs.ruby-lang.org/en/master/io_streams_rdoc.html]. | ||
* | ||
* Commonly used to simulate <code>$stdio</code> or <code>$stderr</code> | ||
* === About the Examples | ||
* | ||
* === Examples | ||
* Examples on this page assume that \StringIO has been required: | ||
* | ||
* require 'stringio' | ||
* | ||
* # Writing stream emulation | ||
* io = StringIO.new | ||
* io.puts "Hello World" | ||
* io.string #=> "Hello World\n" | ||
* | ||
* # Reading stream emulation | ||
* io = StringIO.new "first\nsecond\nlast\n" | ||
* io.getc #=> "f" | ||
* io.gets #=> "irst\n" | ||
* io.read #=> "second\nlast\n" | ||
*/ | ||
void | ||
Init_stringio(void) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mode
is defaulted tor
ifstring
is frozen.Is this worth to describe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to ::new and ::open..