From 3db3627ffba7e8793427b5336d9c48bc422682a0 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Wed, 17 Sep 2025 21:04:29 +0100 Subject: [ruby/erb] [DOC] More on encodings https://github.com/ruby/erb/commit/d5f6f65a89 --- lib/erb.rb | 41 +++++++++++++++++++++++++++-------------- 1 file 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 +# template = ERB.new(s) +# s.encoding # => # +# template.encoding # => # +# template.result.encoding # => # +# ``` +# +# You can specify a different encoding by adding a [magic comment][magic comments] # at the top of the given string: # # ``` -# s = < -# -# Some text. -# EOF -# # => "<%#-*- coding: Big5 -*-%>\n\nSome text.\n" -# s.encoding -# # => # -# ERB.new(s).result.encoding -# # => # +# <%# Comment. %> +# EOT +# template = ERB.new(s) +# s.encoding # => # +# template.encoding # => # +# template.result.encoding # => # # ``` # # ## 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 -- cgit v1.2.3