From: "zverok (Victor Shepelev) via ruby-core" Date: 2023-02-25T17:50:46+00:00 Subject: [ruby-core:112607] [Ruby master Feature#19458] Expose HEREDOC identifier Issue #19458 has been updated by zverok (Victor Shepelev). File clipboard-202302251947-5owjc.png added I came to the same idea as this ticket independently in a [half-joke discussion](https://bugs.ruby-lang.org/issues/19015#note-5), and I find it tempting, too. Even planned to submit my own proposal once I'll have it clearly formed in my head. > To my understanding, the reason you can freely choose the heredoc identifier is not to label the language of the content, but to allow any string to appear in it. First, there is quite widespread agreement to use embedded language's name as a heredoc identifier. So widespread, in fact, that many editors give it as a hint for highlighting: ![](clipboard-202302251947-5owjc.png) (SublimeText's standard Ruby highlighting.) Second, even ignoring this argument, the delimiter of HEREdoc is "user's data," so it is up to the user to know what it means, and it is frequently meaningful for them, so programmatic access to this information might be valuable for many contexts. Of course, many users do some "regular" stuff (like `STR` or `EOS`), but others use the possibility to "tag" strings, and if Ruby will give the access to this "tag", it might find many good usages. ---------------------------------------- Feature #19458: Expose HEREDOC identifier https://bugs.ruby-lang.org/issues/19458#change-102054 * 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. ---Files-------------------------------- clipboard-202302251947-5owjc.png (16.4 KB) -- 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/