From e68934e0be945256e22d0ef09a99757d070a8031 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Wed, 17 Sep 2025 20:18:51 +0100 Subject: [PATCH 1/3] [DOC] Doc for ERB#run --- lib/erb.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/erb.rb b/lib/erb.rb index bb2baf0..da8c25c 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -873,7 +873,13 @@ def set_eoutvar(compiler, eoutvar = '_erbout') compiler.post_cmd = [eoutvar] end - # Generate results and print them. (see ERB#result) + # :markup: markdown + # + # :call-seq: + # run(binding = new_toplevel) -> nil + # + # Like #result, but prints the result string (instead of returning it); + # returns `nil`. def run(b=new_toplevel) print self.result(b) end From a9245b211b2bdc08a35dad9dd6b815a61fbc0fab Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Wed, 17 Sep 2025 21:04:29 +0100 Subject: [PATCH 2/3] [DOC] More on encodings --- lib/erb.rb | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/lib/erb.rb b/lib/erb.rb index da8c25c..fa3d7dd 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -511,24 +511,32 @@ # # ## 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 # => # # ``` # # ## Plain Text Example @@ -830,7 +838,12 @@ def make_compiler(trim_mode) # 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 # The optional _filename_ argument passed to Kernel#eval when the ERB code From 212c5a3c7812e8bf39ebe631e333a700e5e62b80 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Wed, 17 Sep 2025 21:27:28 +0100 Subject: [PATCH 3/3] [DOC] Doc for #new_toplevel --- lib/erb.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/erb.rb b/lib/erb.rb index fa3d7dd..4114394 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -942,10 +942,21 @@ def result_with_hash(hash) result(b) end - ## - # Returns a new binding each time *near* TOPLEVEL_BINDING for runs that do - # not specify a binding. - + # :markup: markdown + # + # :call-seq: + # new_toplevel(symbols) -> new_binding + # + # Returns a new binding based on `TOPLEVEL_BINDING`; + # used to create a default binding for a call to #result. + # + # See [Default Binding][default binding]. + # + # Argument `symbols` is an array of symbols; + # each symbol `symbol` is used to define (unless already defined) a variable in the binding + # whose name is `symbol` and whose value is `nil`. + # + # [default binding]: rdoc-ref:ERB@Default+Binding def new_toplevel(vars = nil) b = TOPLEVEL_BINDING if vars