summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-02-26 16:16:40 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-02-26 16:23:04 +0900
commit62c15833531d85134783ba5e1d6cef8b7a4488da (patch)
tree49b101b601a5f33f9488437ffe1b22b4e2573605 /doc
parent26ffda2fd217651e73eb71e6da8f89eb17866f9d (diff)
[DOC] Place a non-US-ASCII document in a document-specific script
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5601
Diffstat (limited to 'doc')
-rw-r--r--doc/.document1
-rw-r--r--doc/transcode.rb50
2 files changed, 51 insertions, 0 deletions
diff --git a/doc/.document b/doc/.document
index f35cd4769b..b52a2104a7 100644
--- a/doc/.document
+++ b/doc/.document
@@ -1,4 +1,5 @@
*.md
+*.rb
*.rdoc
NEWS-*
syntax
diff --git a/doc/transcode.rb b/doc/transcode.rb
new file mode 100644
index 0000000000..2c70a250e9
--- /dev/null
+++ b/doc/transcode.rb
@@ -0,0 +1,50 @@
+class String
+ # call-seq:
+ # encode(dst_encoding = Encoding.default_internal, **enc_opts) -> string
+ # encode(dst_encoding, src_encoding, **enc_opts) -> string
+ #
+ # Returns a copy of +self+ transcoded as determined by +dst_encoding+.
+ # By default, raises an exception if +self+
+ # contains an invalid byte or a character not defined in +dst_encoding+;
+ # that behavior may be modified by encoding options; see below.
+ #
+ # With no arguments:
+ #
+ # - Uses the same encoding if <tt>Encoding.default_internal</tt> is +nil+
+ # (the default):
+ #
+ # Encoding.default_internal # => nil
+ # s = "Ruby\x99".force_encoding('Windows-1252')
+ # s.encoding # => #<Encoding:Windows-1252>
+ # s.bytes # => [82, 117, 98, 121, 153]
+ # t = s.encode # => "Ruby\x99"
+ # t.encoding # => #<Encoding:Windows-1252>
+ # t.bytes # => [82, 117, 98, 121, 226, 132, 162]
+ #
+ # - Otherwise, uses the encoding <tt>Encoding.default_internal</tt>:
+ #
+ # Encoding.default_internal = 'UTF-8'
+ # t = s.encode # => "Ruby™"
+ # t.encoding # => #<Encoding:UTF-8>
+ #
+ # With only argument +dst_encoding+ given, uses that encoding:
+ #
+ # s = "Ruby\x99".force_encoding('Windows-1252')
+ # s.encoding # => #<Encoding:Windows-1252>
+ # t = s.encode('UTF-8') # => "Ruby™"
+ # t.encoding # => #<Encoding:UTF-8>
+ #
+ # With arguments +dst_encoding+ and +src_encoding+ given,
+ # interprets +self+ using +src_encoding+, encodes the new string using +dst_encoding+:
+ #
+ # s = "Ruby\x99"
+ # t = s.encode('UTF-8', 'Windows-1252') # => "Ruby™"
+ # t.encoding # => #<Encoding:UTF-8>
+ #
+ # Optional keyword arguments +enc_opts+ specify encoding options;
+ # see {Encoding Options}[rdoc-ref:encoding.rdoc@Encoding+Options].
+ def encode(dst_encoding = Encoding.default_internal, **enc_opts)
+ # Pseudo code
+ Builtin.str_transcode!(...)
+ end
+end