new(string = "") -> String
[permalink][rdoc]new(string = "", encoding: string.encoding, capacity: 127) -> String
new(string = "", encoding: string.encoding, capacity: string.bytesize) -> String
string と同じ内容の新しい文字列を作成して返します。引数を省略した場合は空文字列を生成して返します。
text = "hoge".encode("EUC-JP")
no_option = String.new(text) # => "hoge"
no_option.encoding == Encoding::EUC_JP # => true
with_encoding = String.new(text, encoding: "UTF-8") # => "hoge"
with_encoding.encoding == Encoding::UTF_8 # => true
String.new("test", encoding: "UTF-8", capacity: 100_000) # => "test"