mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[DOC] Enhanced RDoc for String (#5751)
Adds to doc for String.new, also making it compliant with documentation_guide.rdoc. Fixes some broken links in io.c (that I failed to correct yesterday).
This commit is contained in:
parent
4d2623ead2
commit
7be4d900f0
Notes:
git
2022-04-03 04:27:12 +09:00
Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
4 changed files with 49 additions and 37 deletions
|
@ -1,36 +1,50 @@
|
||||||
Returns a new \String that is a copy of +string+.
|
Returns a new \String that is a copy of +string+.
|
||||||
|
|
||||||
With no arguments, returns the empty string with the Encoding <tt>ASCII-8BIT</tt>:
|
With no arguments, returns the empty string with the Encoding <tt>ASCII-8BIT</tt>:
|
||||||
|
|
||||||
s = String.new
|
s = String.new
|
||||||
s # => ""
|
s # => ""
|
||||||
s.encoding # => #<Encoding:ASCII-8BIT>
|
s.encoding # => #<Encoding:ASCII-8BIT>
|
||||||
|
|
||||||
With the single \String argument +string+, returns a copy of +string+
|
With optional argument +string+ and no keyword arguments,
|
||||||
with the same encoding as +string+:
|
returns a copy of +string+ with the same encoding:
|
||||||
s = String.new('Que veut dire ça?')
|
|
||||||
s # => "Que veut dire ça?"
|
|
||||||
s.encoding # => #<Encoding:UTF-8>
|
|
||||||
|
|
||||||
Literal strings like <tt>""</tt> or here-documents always use
|
String.new('foo') # => "foo"
|
||||||
{script encoding}[rdoc-ref:Encoding@Script+Encoding], unlike String.new.
|
String.new('тест') # => "тест"
|
||||||
|
String.new('こんにちは') # => "こんにちは"
|
||||||
|
|
||||||
With keyword +encoding+, returns a copy of +str+
|
(Unlike \String.new,
|
||||||
with the specified encoding:
|
a {string literal}[rdoc-ref:syntax/literals.rdoc@String+Literals] like <tt>''</tt> or a
|
||||||
s = String.new(encoding: 'ASCII')
|
{here document literal}[rdoc-ref:syntax/literals.rdoc@Here+Document+Literals]
|
||||||
s.encoding # => #<Encoding:US-ASCII>
|
always has {script encoding}[rdoc-ref:encodings.rdoc@Script+Encoding].)
|
||||||
s = String.new('foo', encoding: 'ASCII')
|
|
||||||
s.encoding # => #<Encoding:US-ASCII>
|
|
||||||
|
|
||||||
Note that these are equivalent:
|
With optional keyword argument +encoding+, returns a copy of +string+
|
||||||
s0 = String.new('foo', encoding: 'ASCII')
|
with the specified encoding;
|
||||||
s1 = 'foo'.force_encoding('ASCII')
|
the +encoding+ may be an Encoding object, an encoding name,
|
||||||
s0.encoding == s1.encoding # => true
|
or an encoding name alias:
|
||||||
|
|
||||||
With keyword +capacity+, returns a copy of +str+;
|
String.new('foo', encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII>
|
||||||
the given +capacity+ may set the size of the internal buffer,
|
String.new('foo', encoding: 'US-ASCII').encoding # => #<Encoding:US-ASCII>
|
||||||
which may affect performance:
|
String.new('foo', encoding: 'ASCII').encoding # => #<Encoding:US-ASCII>
|
||||||
String.new(capacity: 1) # => ""
|
|
||||||
String.new(capacity: 4096) # => ""
|
The given encoding need not be valid for the string's content,
|
||||||
|
and that validity is not checked:
|
||||||
|
|
||||||
|
s = String.new('こんにちは', encoding: 'ascii')
|
||||||
|
s.valid_encoding? # => false
|
||||||
|
|
||||||
|
But the given +encoding+ itself is checked:
|
||||||
|
|
||||||
|
String.new('foo', encoding: 'bar') # Raises ArgumentError.
|
||||||
|
|
||||||
|
With optional keyword argument +capacity+, returns a copy of +string+
|
||||||
|
(or an empty string, if +string+ is not given);
|
||||||
|
the given +capacity+ is advisory only,
|
||||||
|
and may or may not set the size of the internal buffer,
|
||||||
|
which may in turn affect performance:
|
||||||
|
|
||||||
|
String.new(capacity: 1)
|
||||||
|
String.new('foo', capacity: 4096)
|
||||||
|
|
||||||
The +string+, +encoding+, and +capacity+ arguments may all be used together:
|
The +string+, +encoding+, and +capacity+ arguments may all be used together:
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ class String
|
||||||
# t.encoding # => #<Encoding:UTF-8>
|
# t.encoding # => #<Encoding:UTF-8>
|
||||||
#
|
#
|
||||||
# Optional keyword arguments +enc_opts+ specify encoding options;
|
# Optional keyword arguments +enc_opts+ specify encoding options;
|
||||||
# see {Encoding Options}[rdoc-ref:Encoding@Encoding+Options].
|
# see {Encoding Options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
def encode(dst_encoding = Encoding.default_internal, **enc_opts)
|
def encode(dst_encoding = Encoding.default_internal, **enc_opts)
|
||||||
# Pseudo code
|
# Pseudo code
|
||||||
Primitive.str_encode(...)
|
Primitive.str_encode(...)
|
||||||
|
|
22
io.c
22
io.c
|
@ -7458,7 +7458,7 @@ static VALUE popen_finish(VALUE port, VALUE klass);
|
||||||
* Optional keyword arguments +opts+ specify:
|
* Optional keyword arguments +opts+ specify:
|
||||||
*
|
*
|
||||||
* - {Open options}[rdoc-ref:IO@Open+Options].
|
* - {Open options}[rdoc-ref:IO@Open+Options].
|
||||||
* - {Encoding options}[rdoc-ref:Encoding@Encoding+Options].
|
* - {Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
* - Options for Kernel#spawn.
|
* - Options for Kernel#spawn.
|
||||||
*
|
*
|
||||||
* <b>Forked \Process</b>
|
* <b>Forked \Process</b>
|
||||||
|
@ -8080,7 +8080,7 @@ rb_freopen(VALUE fname, const char *mode, FILE *fp)
|
||||||
* Optional keyword arguments +opts+ specify:
|
* Optional keyword arguments +opts+ specify:
|
||||||
*
|
*
|
||||||
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
||||||
* - {Encoding options}[rdoc-ref:Encoding@Encoding+Options].
|
* - {Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -9012,7 +9012,7 @@ rb_io_make_open_file(VALUE obj)
|
||||||
* Optional keyword arguments +opts+ specify:
|
* Optional keyword arguments +opts+ specify:
|
||||||
*
|
*
|
||||||
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
||||||
* - {Encoding options}[rdoc-ref:Encoding@Encoding+Options].
|
* - {Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
|
@ -9156,7 +9156,7 @@ rb_io_set_encoding_by_bom(VALUE io)
|
||||||
* Optional keyword arguments +opts+ specify:
|
* Optional keyword arguments +opts+ specify:
|
||||||
*
|
*
|
||||||
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
||||||
* - {Encoding options}[rdoc-ref:Encoding@Encoding+Options].
|
* - {Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
|
@ -9835,7 +9835,7 @@ static VALUE argf_readlines(int, VALUE *, VALUE);
|
||||||
* For all forms above, optional keyword arguments specify:
|
* For all forms above, optional keyword arguments specify:
|
||||||
*
|
*
|
||||||
* - {Line Options}[rdoc-ref:IO@Line+Options].
|
* - {Line Options}[rdoc-ref:IO@Line+Options].
|
||||||
* - {Encoding options}[rdoc-ref:Encoding@Encoding+Options].
|
* - {Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
|
@ -11100,7 +11100,7 @@ pipe_pair_close(VALUE rw)
|
||||||
* Optional keyword arguments +opts+ specify:
|
* Optional keyword arguments +opts+ specify:
|
||||||
*
|
*
|
||||||
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
||||||
* - {Encoding Options}[rdoc-ref:Encoding@Encoding+Options].
|
* - {Encoding Options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
*
|
*
|
||||||
* With no block given, returns the two endpoints in an array:
|
* With no block given, returns the two endpoints in an array:
|
||||||
*
|
*
|
||||||
|
@ -11362,7 +11362,7 @@ io_s_foreach(VALUE v)
|
||||||
* Optional keyword arguments +opts+ specify:
|
* Optional keyword arguments +opts+ specify:
|
||||||
*
|
*
|
||||||
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
||||||
* - {Encoding options}[rdoc-ref:Encoding@Encoding+Options].
|
* - {Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
* - {Line Options}[rdoc-ref:IO@Line+Options].
|
* - {Line Options}[rdoc-ref:IO@Line+Options].
|
||||||
*
|
*
|
||||||
* Returns an Enumerator if no block is given.
|
* Returns an Enumerator if no block is given.
|
||||||
|
@ -11460,7 +11460,7 @@ io_s_readlines(VALUE v)
|
||||||
* Optional keyword arguments +opts+ specify:
|
* Optional keyword arguments +opts+ specify:
|
||||||
*
|
*
|
||||||
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
||||||
* - {Encoding options}[rdoc-ref:Encoding@Encoding+Options].
|
* - {Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
* - {Line Options}[rdoc-ref:IO@Line+Options].
|
* - {Line Options}[rdoc-ref:IO@Line+Options].
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -11550,7 +11550,7 @@ seek_before_access(VALUE argp)
|
||||||
* Optional keyword arguments +opts+ specify:
|
* Optional keyword arguments +opts+ specify:
|
||||||
*
|
*
|
||||||
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
||||||
* - {Encoding options}[rdoc-ref:Encoding@Encoding+Options].
|
* - {Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -11741,7 +11741,7 @@ io_s_write(int argc, VALUE *argv, VALUE klass, int binary)
|
||||||
* Optional keyword arguments +opts+ specify:
|
* Optional keyword arguments +opts+ specify:
|
||||||
*
|
*
|
||||||
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
* - {Open Options}[rdoc-ref:IO@Open+Options].
|
||||||
* - {Encoding options}[rdoc-ref:Encoding@Encoding+Options].
|
* - {Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -12825,7 +12825,7 @@ rb_io_internal_encoding(VALUE io)
|
||||||
* and internal encodings for the stream.
|
* and internal encodings for the stream.
|
||||||
*
|
*
|
||||||
* Optional keyword arguments +enc_opts+ specify
|
* Optional keyword arguments +enc_opts+ specify
|
||||||
* {Encoding options}[rdoc-ref:Encoding@Encoding+Options].
|
* {Encoding options}[rdoc-ref:encodings.rdoc@Encoding+Options].
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
4
string.c
4
string.c
|
@ -1813,9 +1813,7 @@ rb_ec_str_resurrect(struct rb_execution_context_struct *ec, VALUE str)
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* String.new(string = '') -> new_string
|
* String.new(string = '', **opts) -> new_string
|
||||||
* String.new(string = '', encoding: encoding) -> new_string
|
|
||||||
* String.new(string = '', capacity: size) -> new_string
|
|
||||||
*
|
*
|
||||||
* :include: doc/string/new.rdoc
|
* :include: doc/string/new.rdoc
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue