Heads up: This description was created by AI and might not be 100% accurate.

with_value.rb

This Ruby code snippet demonstrates how to use the “«~” operator to create a heredoc (i.e., a here document) in Ruby. The “«~” operator is used to specify that the following indented lines should be treated as a heredoc, which allows for more readable and flexible formatting of text.

In this code snippet, we define a variable value with the value 'ruby', and then use the “«~” operator to create a heredoc with the same name (doc). The heredoc is assigned the value of the indented lines following it, which in this case is just the string 'ruby'.

Note that the heredoc is defined by indenting the lines below the “«~” operator. The indentation should be consistent throughout the heredoc, and should not contain any leading or trailing whitespace. Additionally, the heredoc should not be terminated with a line break.

Ruby code snippet

value = 'ruby'
#=> "ruby"
doc = <<~EOL
  #{value}
EOL
#=> "ruby\n"

Executed with Ruby 3.4.4.