ruby/doc/string/b.rdoc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

17 lines
515 B
Plaintext
Raw Normal View History

Returns a copy of +self+ that has ASCII-8BIT encoding;
the underlying bytes are not modified:
s = "\x99"
s.encoding # => #<Encoding:UTF-8>
t = s.b # => "\x99"
t.encoding # => #<Encoding:ASCII-8BIT>
s = "\u4095" # => "䂕"
s.encoding # => #<Encoding:UTF-8>
s.bytes # => [228, 130, 149]
t = s.b # => "\xE4\x82\x95"
t.encoding # => #<Encoding:ASCII-8BIT>
t.bytes # => [228, 130, 149]
2025-05-15 14:58:57 -05:00
Related: see {Converting to New String}[rdoc-ref:String@Converting+to+New+String].