Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6bd72a6

Browse files
BurdetteLamarmatzbot
authored andcommitted
[DOC] Enhanced RDoc for StringIO (#34)
Treated: - #lineno - #lineno= - #binmode - #reopen - #pos - #pos= - #rewind - #seek - #sync - #each_byte
1 parent b2ba71d commit 6bd72a6

File tree

1 file changed

+52
-31
lines changed

1 file changed

+52
-31
lines changed

ext/stringio/stringio.c

+52-31
Original file line numberDiff line numberDiff line change
@@ -649,13 +649,10 @@ strio_copy(VALUE copy, VALUE orig)
649649

650650
/*
651651
* call-seq:
652-
* strio.lineno -> integer
652+
* lineno -> current_line_number
653653
*
654-
* Returns the current line number. The stream must be
655-
* opened for reading. +lineno+ counts the number of times +gets+ is
656-
* called, rather than the number of newlines encountered. The two
657-
* values will differ if +gets+ is called with a separator other than
658-
* newline. See also the <code>$.</code> variable.
654+
* Returns the current line number in +self+;
655+
* see {Line Number}[https://docs.ruby-lang.org/en/master/io_streams_rdoc.html#label-Line+Number].
659656
*/
660657
static VALUE
661658
strio_get_lineno(VALUE self)
@@ -665,10 +662,10 @@ strio_get_lineno(VALUE self)
665662

666663
/*
667664
* call-seq:
668-
* strio.lineno = integer -> integer
665+
* lineno = new_line_number -> new_line_number
669666
*
670-
* Manually sets the current line number to the given value.
671-
* <code>$.</code> is updated only on the next read.
667+
* Sets the current line number in +self+ to the given +new_line_number+;
668+
* see {Line Number}[https://docs.ruby-lang.org/en/master/io_streams_rdoc.html#label-Line+Number].
672669
*/
673670
static VALUE
674671
strio_set_lineno(VALUE self, VALUE lineno)
@@ -679,9 +676,10 @@ strio_set_lineno(VALUE self, VALUE lineno)
679676

680677
/*
681678
* call-seq:
682-
* strio.binmode -> stringio
679+
* binmode -> self
683680
*
684-
* Puts stream into binary mode. See IO#binmode.
681+
* Sets the data mode in +self+ to binary mode;
682+
* see {Data Mode}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Data+Mode].
685683
*
686684
*/
687685
static VALUE
@@ -705,11 +703,27 @@ strio_binmode(VALUE self)
705703

706704
/*
707705
* call-seq:
708-
* strio.reopen(other_StrIO) -> strio
709-
* strio.reopen(string, mode) -> strio
706+
* reopen(other, mode = 'r+') -> self
707+
*
708+
* Reinitializes the stream with the given +other+ (string or StringIO) and +mode+;
709+
* see IO.new:
710+
*
711+
* StringIO.open('foo') do |strio|
712+
* p strio.string
713+
* strio.reopen('bar')
714+
* p strio.string
715+
* other_strio = StringIO.new('baz')
716+
* strio.reopen(other_strio)
717+
* p strio.string
718+
* other_strio.close
719+
* end
720+
*
721+
* Output:
722+
*
723+
* "foo"
724+
* "bar"
725+
* "baz"
710726
*
711-
* Reinitializes the stream with the given <i>other_StrIO</i> or _string_
712-
* and _mode_ (see StringIO#new).
713727
*/
714728
static VALUE
715729
strio_reopen(int argc, VALUE *argv, VALUE self)
@@ -723,10 +737,12 @@ strio_reopen(int argc, VALUE *argv, VALUE self)
723737

724738
/*
725739
* call-seq:
726-
* strio.pos -> integer
727-
* strio.tell -> integer
740+
* pos -> stream_position
741+
*
742+
* Returns the current position (in bytes);
743+
* see {Position}[https://docs.ruby-lang.org/en/master/io_streams_rdoc.html#label-Position].
728744
*
729-
* Returns the current offset (in bytes).
745+
* StringIO#tell is an alias for StringIO#pos.
730746
*/
731747
static VALUE
732748
strio_get_pos(VALUE self)
@@ -736,9 +752,10 @@ strio_get_pos(VALUE self)
736752

737753
/*
738754
* call-seq:
739-
* strio.pos = integer -> integer
755+
* pos = new_position -> new_position
740756
*
741-
* Seeks to the given position (in bytes).
757+
* Sets the current position (in bytes);
758+
* see {Position}[https://docs.ruby-lang.org/en/master/io_streams_rdoc.html#label-Position].
742759
*/
743760
static VALUE
744761
strio_set_pos(VALUE self, VALUE pos)
@@ -754,10 +771,11 @@ strio_set_pos(VALUE self, VALUE pos)
754771

755772
/*
756773
* call-seq:
757-
* strio.rewind -> 0
774+
* rewind -> 0
758775
*
759-
* Positions the stream to the beginning of input, resetting
760-
* +lineno+ to zero.
776+
* Sets the current position and line number to zero;
777+
* see {Position}[https://docs.ruby-lang.org/en/master/io_streams_rdoc.html#label-Position]
778+
* and {Line Number}[https://docs.ruby-lang.org/en/master/io_streams_rdoc.html#label-Line+Number].
761779
*/
762780
static VALUE
763781
strio_rewind(VALUE self)
@@ -770,10 +788,11 @@ strio_rewind(VALUE self)
770788

771789
/*
772790
* call-seq:
773-
* strio.seek(amount, whence=SEEK_SET) -> 0
791+
* seek(offset, whence = SEEK_SET) -> 0
774792
*
775-
* Seeks to a given offset _amount_ in the stream according to
776-
* the value of _whence_ (see IO#seek).
793+
* Sets the current position to the given integer +offset+ (in bytes),
794+
* with respect to a given constant +whence+;
795+
* see {Position}[https://docs.ruby-lang.org/en/master/io_streams_rdoc.html#label-Position].
777796
*/
778797
static VALUE
779798
strio_seek(int argc, VALUE *argv, VALUE self)
@@ -809,9 +828,9 @@ strio_seek(int argc, VALUE *argv, VALUE self)
809828

810829
/*
811830
* call-seq:
812-
* strio.sync -> true
831+
* sync -> true
813832
*
814-
* Returns +true+ always.
833+
* Returns +true+; implemented only for compatibility with other stream classes.
815834
*/
816835
static VALUE
817836
strio_get_sync(VALUE self)
@@ -826,10 +845,12 @@ strio_get_sync(VALUE self)
826845

827846
/*
828847
* call-seq:
829-
* strio.each_byte {|byte| block } -> strio
830-
* strio.each_byte -> anEnumerator
848+
* each_byte {|byte| ... } -> self
849+
*
850+
* With a block given, calls the block with each remaining byte in the stream;
851+
* see {Byte IO}[https://docs.ruby-lang.org/en/master/io_streams_rdoc.html#label-Byte+IO].
831852
*
832-
* See IO#each_byte.
853+
* With no block given, returns an enumerator.
833854
*/
834855
static VALUE
835856
strio_each_byte(VALUE self)

0 commit comments

Comments
 (0)