summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/erb.rb41
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