Issue #19458 has been updated by rubyFeedback (robert heiler).
I have no particularly strong opinion either way.
But I wanted to comment on zverok's statement:
[...] use the possibility to "tag" strings,
and if Ruby
will give the access to this "tag", it might find many
good usages.
I agree somwhat with that opinion too.
For instance, I also suggested to propose an extension to case/when
"interfaces" where we can not only access all case/when entries in
a given method (perhaps only for non-private methods), and merge
different case/when entries, as well as adding methods such as
.to_h or .to_hash to convert it to a hash, and/or to a proc object,
and .call() on it.
My original use case for this, several years ago, was to be able to
autogenerated tab-completion for shells such as bash and zsh. So
that I can know all entries in a case/when menu. For instance:
case x
when 'a','b','c'
'foobar' # all three match to foobar, similar to a Hash where the
# three keys 'a','b' and 'c' would point to
'foobar'
end
Since then case/when menu got even better support - see pattern
matching.
Anyway - making a good proposal that is not-trivial, is quite difficult
actually, so I kind of dropped it, hoping that someone else may find the
motivation to do a good proposal here one day. :D
So, to come to this issue - I think if you look at it from an extended
point of view, then being able to know associated use cases could indeed
be interesting, so on that topic I concur with zverok. That does not
mean I am in favour of the suggestion here, or in disfavour - I just think
it may indeed be worthy to explore use case here. I have not had a huge
need to use ERB per se, but I do happen to read in a .md file
----------------------------------------
Feature #19458: Expose HEREDOC identifier
https://bugs.ruby-lang.org/issues/19458#change-102062
* 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.
---Files--------------------------------
clipboard-202302251947-5owjc.png (16.4 KB)
--
https://bugs.ruby-lang.org/