From: "zverok (Victor Shepelev)" Date: 2022-09-22T08:46:33+00:00 Subject: [ruby-core:109994] [Ruby master Feature#19015] Language extension by a heredoc Issue #19015 has been updated by zverok (Victor Shepelev). I am not sure how serious this is (considering the "Apr 1" notice), but I have somewhat adjacent thought: In many modern code editors, highlighting of several different languages in the same file is supported. Namely, SublimeText (I am not sure about the others, but I suppose the idea is not unique) understands this: ```ruby query = <<~SQL SELECT * FROM users WHERE status='active SQL DB.execute(query) ``` ...and highlights the code inside a heredoc as SQL. I am thinking that maybe some way of preserving the "tag" it was surrounded (in String metadata?.. Or, making HEREDOC-produced object a different class, a descendant of String with extra functionality) would be generically useful. It will allow implementing the @ko1 's example just like this: ```ruby require 'erb' def heredoc_extension_erb str, b ERB.new(str).run(b) end name = 'ko1' html = <<~erb
Hello <%= name %>
erb puts execute_heredoc(html, binding) # where... def execute_heredoc(str, binding) case str.__tag__ when 'erb' ERB.new(str).run(binding) # .... end end ``` The idea can even be expanded to provide additional metadata (currently invalid syntax, so no compatibility would be broken): ```ruby html = <<~erb(trim_mode="%>")
Hello <%= name %>
erb ``` WDYT? ---------------------------------------- Feature #19015: Language extension by a heredoc https://bugs.ruby-lang.org/issues/19015#change-99244 * Author: ko1 (Koichi Sasada) * Status: Open * Priority: Normal ---------------------------------------- This propose new heredoc extension with `<Hello <%= name %> erb puts html ``` ## Background / considerations * Sometimes we write Ruby syntax string with `<