diff options
| author | BurdetteLamar <burdettelamar@yahoo.com> | 2025-09-17 21:04:29 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2025-09-17 20:49:35 +0000 |
| commit | 3db3627ffba7e8793427b5336d9c48bc422682a0 (patch) | |
| tree | 111ca877b3755bc79b01ab3d9ce487c31b202897 | |
| parent | ffbcbe20ff4d6f3958f3e07f4f1f7fd0e3bd1740 (diff) | |
[ruby/erb] [DOC] More on encodings
https://github.com/ruby/erb/commit/d5f6f65a89
| -rw-r--r-- | lib/erb.rb | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/lib/erb.rb b/lib/erb.rb index 7f09e670b5..62b83e523c 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -511,24 +511,32 @@ require 'erb/util' # # ## Encodings # -# In general, an \ERB result string (or Ruby code generated by \ERB) -# has the same encoding as the string originally passed to ERB.new; -# see [Encoding][encoding]. +# An \ERB template has an [encoding][encoding], +# which is by default the encoding of the source string; +# the result string will also have that encoding. # -# You can specify the output encoding by adding a [magic comment][magic comments] +# ``` +# s = <<EOT +# <%# Comment. %> +# EOT +# template = ERB.new(s) +# s.encoding # => #<Encoding:UTF-8> +# template.encoding # => #<Encoding:UTF-8> +# template.result.encoding # => #<Encoding:UTF-8> +# ``` +# +# You can specify a different encoding by adding a [magic comment][magic comments] # at the top of the given string: # # ``` -# s = <<EOF +# s = <<EOT # <%#-*- coding: Big5 -*-%> -# -# Some text. -# EOF -# # => "<%#-*- coding: Big5 -*-%>\n\nSome text.\n" -# s.encoding -# # => #<Encoding:UTF-8> -# ERB.new(s).result.encoding -# # => #<Encoding:Big5> +# <%# Comment. %> +# EOT +# template = ERB.new(s) +# s.encoding # => #<Encoding:UTF-8> +# template.encoding # => #<Encoding:Big5> +# template.result.encoding # => #<Encoding:Big5> # ``` # # ## Error Reporting @@ -873,7 +881,12 @@ class ERB # The Ruby code generated by ERB attr_reader :src - # The encoding to eval + # :markup: markdown + # + # Returns the encoding of `self`; + # see [encoding][encoding]. + # + # [encoding]: https://docs.ruby-lang.org/en/master/Encoding.html attr_reader :encoding # :markup: markdown |
