If I have a method
def some_method p = {} string = <<-MY_TERMINATOR Example text blah blah lorem ipsum something or another MY_TERMINATOR end
how can I access the variable p[:name] from within the heredoc?
What is heredoc? Heredoc allows us to specify a string as a block of texts where new lines and indentations are maintained. This is useful in Ruby for various cases like specifying multiline text strings, multiline method dynamic definitions and more.
String Interpolation, it is all about combining strings together, but not by using the + operator. String Interpolation works only when we use double quotes (“”) for the string formation. String Interpolation provides an easy way to process String literals.
You can interpolate just like in normal strings
<<-TERMINATOR Example #{p[:name]} blah blah blah TERMINATOR
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With