From: "sawa (Tsuyoshi Sawada) via ruby-core" Date: 2023-02-23T00:31:06+00:00 Subject: [ruby-core:112539] [Ruby master Feature#19458] Expose HEREDOC identifier Issue #19458 has been updated by sawa (Tsuyoshi Sawada). It looks like nonsense. To my understanding, the reason you can freely choose the heredoc identifier is not to mark the language of the content, but to allow any string to appear in it. In your example, if you had a line within your string that is just `ERB` besides spaces, you need to come up with an identifier that is different from `ERB` (as well as any other lines in your string). That is what the freedom of the identifier is for. The purpose of identifier is just to terminate a string, and should not carry any significant information. Some editors can hilight the contents of heredoc in different languages depending on the identifier, but that is out of the scope of Ruby, and that only works probabilistically, i.e., under the assumption that you will **probably** not have a line that is identical to the common file extension of the language you are writing the heredoc in. Whether the heredoc iditifier is ERB or MD is nothing more significant than whether the string was written as `"..."`, `'...'`, ?x, `%q{...}`, or `%Q|...|`, etc. Relying on the heredoc identifier to infer the language is also not clean. If you need to notify the language as well as the string, you should pass two arguments to the method: perhaps a symbol representing the language, and the string. ---------------------------------------- Feature #19458: Expose HEREDOC identifier https://bugs.ruby-lang.org/issues/19458#change-101985 * Author: joelhawksley (Joel Hawksley) * Status: Open * Priority: Normal ---------------------------------------- I���d like to have access to the HEREDOC identifier. In the ViewComponent framework I help maintain, we added a method to declare a template as such: ```ruby class Component erb_template <<~ERB

Hello, <%= @name %>!

ERB end ``` I'd prefer to be able to write: ```ruby class Component template <<~ERB

Hello, <%= @name %>!

ERB end ``` And be able to see that the argument passed to `.template` was from a HEREDOC with an `ERB` identifier, which would allow me to use the correct template handler to compile the template. I could see this being implemented: 1) As a new property of String, such as `identifier` or `heredoc_identifier`. 2) By having HEREDOCs return a subclass of String that includes an `identifier` property. I'd be happy to work on implementing this change. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/