[ruby-core:117794] [Ruby master Bug#20474] Heredoc common leading whitespace calculation question
From:
"kddnewton (Kevin Newton) via ruby-core" <ruby-core@...>
Date:
2024-05-07 18:32:30 UTC
List:
ruby-core #117794
Issue #20474 has been reported by kddnewton (Kevin Newton).
----------------------------------------
Bug #20474: Heredoc common leading whitespace calculation question
https://bugs.ruby-lang.org/issues/20474
* Author: kddnewton (Kevin Newton)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I think I understand that <<~ will strip common leading whitespace from all lines. However, I am confused by the following example:
```ruby
eval("<<~H\n \nh\n \nH\n")
```
In this example, the heredoc has 3 lines: " \n", "h\n", and " \n". The common leading whitespace is definitely 0, because of the 2nd line.
However, the string is equal to `"\nh\n\n"`. In fact, no matter how many spaces you put _before_ the `h`, it will always be equal to `"\nh\n\n"`.
I'm not sure if this is a bug, or even what is happening here. Could someone explain?
--
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/