开发者

Can I access a variable within a heredoc in Ruby?

开发者 https://www.devze.com 2023-01-08 15:45 出处:网络
If I have a method def some_method p = {} string = <<-MY_TERMINATOR Example text blah blah lorem ipsum something or another

If I have a method

  def some_method p = {}
    string = <<-MY_TERMINATOR
      Example text blah blah
      lorem ipsum something or another
    MY_TERMINATOR
  end

开发者_StackOverflowhow can I access the variable p[:name] from within the heredoc?


You can interpolate just like in normal strings

<<-TERMINATOR
  Example #{p[:name]} blah blah blah
TERMINATOR
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号