def get_val
100
end
def testcode
s=<<EOS
This is a sample string that references a variable whose value is: #{get_val}
Incrementing the value: #{get_val + 1}
EOS
puts s
end
testcode
在Python中,我想创建一个带有嵌入式表达式的字符串块。在Ruby中,代码如下所示:def get_val 100 end def testcode s = << [[
f"..{get_val()+1}..."
#