[#112457] [Ruby master Feature#19443] Cache `Process.pid` — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Issue #19443 has been reported by byroot (Jean Boussier).
16 messages
2023/02/16
[#112584] [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system — "normalperson (Eric Wong) via ruby-core" <ruby-core@...>
Issue #19465 has been reported by normalperson (Eric Wong).
9 messages
2023/02/25
[#112595] [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— "nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
2023/02/25
SXNzdWUgIzE5NDY1IGhhcyBiZWVuIHVwZGF0ZWQgYnkgbm9idSAoTm9idXlvc2hpIE5ha2FkYSku
[#112613] Re: [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— Eric Wong via ruby-core <ruby-core@...>
2023/02/26
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@ml.ruby-lang.org> wrote:
[#112615] Re: [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— SHIBATA Hiroshi via ruby-core <ruby-core@...>
2023/02/27
MzUxMzZlMWU5YzIzMmFkN2EwMzQwN2I5OTJiMmU4NmI2ZGY0M2Y2MyBpcyBicm9rZW4gd2l0aCBg
[#112626] Re: [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— Eric Wong via ruby-core <ruby-core@...>
2023/02/28
```
[ruby-core:112321] [Ruby master Feature#19428] Adding a "piped heredoc" feature
From:
"naruse (Yui NARUSE) via ruby-core" <ruby-core@...>
Date:
2023-02-10 02:42:45 UTC
List:
ruby-core #112321
Issue #19428 has been updated by naruse (Yui NARUSE).
I came up with another idea after I read your proposal:
```
options = {
name: "My Nice Options",
description: <<|,
| This is a cool set of options.
| You Can put what you like here.
details: <<|,
| Some more stuff here...
| This will only be indented 2 spaces.
| And this 4 spaces.
| And this 2 spaces again.
| Back to the "left" side.
```
----------------------------------------
Feature #19428: Adding a "piped heredoc" feature
https://bugs.ruby-lang.org/issues/19428#change-101766
* Author: shreeve (Steve Shreeve)
* Status: Open
* Priority: Normal
----------------------------------------
Hello,
I hope this is the correct place to post a small feature request.
HEREDOC's are awesome! There are several used within Ruby:
```ruby
<<END
Have to left justify this
END
<<-INDENTED
Still left justified, but indented ending
INDENTED
<<~SQUIGGLY
I can indent content it will be smartly "dedented/undented". Looks nicer.
SQUIGGLY
```
I love using the SQUIGGLY heredoc, which will strip off the minimum whitespace from the front of each line in the heredoc. I often do something like this:
```ruby
options = {
name: "My Nice Options",
description: <<~END
This is a cool set of options.
You Can put what you like here.
END
}
```
If you need to continue with the above, you can add a comma after like this:
```ruby
options = {
name: "My Nice Options",
description: <<~END,
This is a cool set of options.
You Can put what you like here.
END
details: <<~END,
Some more stuff here...
This will only be indented 2 spaces.
And this 4 spaces.
And this 2 spaces again.
Back to the "left" side.
END
}
```
You can even get a little squirrely and use an empty string for a heredoc terminator:
```ruby
options = {
name: "My Nice Options",
description: <<~"",
This is a cool set of options.
You Can put what you like here.
details: <<~"",
Some more stuff here...
This will only be indented 2 spaces.
And this 4 spaces.
And this 2 spaces again.
Back to the "left" side.
}
```
There's one variation that I think would be nice to add, I call it a "piped heredoc". It would essentially work like the squiggly heredoc, but the "terminator" would be the next line that is not indented, and thus not "part of the heredoc".
Here's an example:
```ruby
options = {
name: "My Nice Options",
description: <<|,
This is a cool set of options.
You Can put what you like here.
details: <<|,
Some more stuff here...
This will only be indented 2 spaces.
And this 4 spaces.
And this 2 spaces again.
Back to the "left" side.
}
```
Since the leading whitespace is used to tell when the heredoc ends, there is no need for an explicit terminator.
You could add one if you'd like to indicate the flavor of the content, for syntax highlighters, but it's value is ignored:
```ruby
options = {
name: "My Nice Options",
description: <<|RUBY,
users.each do |user|
user.pay_daily_bonus!
end
details: <<|,
Some more stuff here...
This will only be indented 2 spaces.
And this 4 spaces.
And this 2 spaces again.
Back to the "left" side.
}
```
In the above, the "RUBY" is not really needed, but it is a hint to format that block as Ruby code.
This tweak to Ruby's heredocs seems like it could make Ruby syntax easy and fun to read.
--
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/