D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
String
/
Filename :
new-c.ri
back
Copy
U:RDoc::AnyMethod[iI"new:ETI"String::new;TT:publico:RDoc::Markup::Document:@parts[ o:RDoc::Markup::Paragraph; [I"6Returns a new \String that is a copy of +string+.;To:RDoc::Markup::BlankLine o; ; [I"WWith no arguments, returns the empty string with the Encoding <tt>ASCII-8BIT</tt>:;T@o:RDoc::Markup::Verbatim; [I"s = String.new ;TI"s # => "" ;TI",s.encoding # => #<Encoding:ASCII-8BIT> ;T:@format0o; ; [I"?With optional argument +string+ and no keyword arguments, ;TI"7returns a copy of +string+ with the same encoding:;T@o;; [I"0String.new('foo') # => "foo" ;TI"9String.new('тест') # => "тест" ;TI"CString.new('こんにちは') # => "こんにちは" ;T; 0o; ; [ I"(Unlike \String.new, ;TI"]a {string literal}[rdoc-ref:syntax/literals.rdoc@String+Literals] like <tt>''</tt> or a ;TI"S{here document literal}[rdoc-ref:syntax/literals.rdoc@Here+Document+Literals] ;TI"Lalways has {script encoding}[rdoc-ref:encodings.rdoc@Script+Encoding].);T@o; ; [ I"KWith optional keyword argument +encoding+, returns a copy of +string+ ;TI""with the specified encoding; ;TI"Athe +encoding+ may be an Encoding object, an encoding name, ;TI"or an encoding name alias:;T@o;; [I"XString.new('foo', encoding: Encoding::US_ASCII).encoding # => #<Encoding:US-ASCII> ;TI"XString.new('foo', encoding: 'US-ASCII').encoding # => #<Encoding:US-ASCII> ;TI"XString.new('foo', encoding: 'ASCII').encoding # => #<Encoding:US-ASCII> ;T; 0o; ; [I"DThe given encoding need not be valid for the string's content, ;TI"&and that validity is not checked:;T@o;; [I":s = String.new('こんにちは', encoding: 'ascii') ;TI""s.valid_encoding? # => false ;T; 0o; ; [I"0But the given +encoding+ itself is checked:;T@o;; [I"@String.new('foo', encoding: 'bar') # Raises ArgumentError. ;T; 0o; ; [ I"KWith optional keyword argument +capacity+, returns a copy of +string+ ;TI"5(or an empty string, if +string+ is not given); ;TI",the given +capacity+ is advisory only, ;TI"=and may or may not set the size of the internal buffer, ;TI"*which may in turn affect performance:;T@o;; [I"String.new(capacity: 1) ;TI"'String.new('foo', capacity: 4096) ;T; 0o; ; [I"LNote that Ruby strings are null-terminated internally, so the internal ;TI"Nbuffer size will be one or more bytes larger than the requested capacity ;TI"depending on the encoding.;T@o; ; [I"QThe +string+, +encoding+, and +capacity+ arguments may all be used together:;T@o;; [I"9String.new('hello', encoding: 'UTF-8', capacity: 25);T; 0: @fileI" string.c;T:0@omit_headings_from_table_of_contents_below0I"3String.new(string = '', **opts) -> new_string ;T0[ I"(p1 = v1, p2 = {});T@UFI"String;TcRDoc::NormalClass00