
Issue #19458 has been updated by sawa (Tsuyoshi Sawada). If you want to keep the string and the markup language information together, then perhaps something like the following is the way to go. Preparation: ```ruby class String def lang_set(lang); tap{@lang = lang} end def lang; @lang end end ``` Using it to write a template: ```ruby class Component template <<~ERB.lang_set(:erb) <h1>Hello, <%= @name %>!</h1> ERB end ``` And then in your `template` code: ```ruby def template(string) lang = string.lang raise "Markup language is not set" unless lang case lang when :erb then erb_template(lang) ... end end ``` ---------------------------------------- Feature #19458: Expose HEREDOC identifier https://bugs.ruby-lang.org/issues/19458#change-102039 * 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 <h1>Hello, <%= @name %>!</h1> ERB end ``` I'd prefer to be able to write: ```ruby class Component template <<~ERB <h1>Hello, <%= @name %>!</h1> 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/