Ruby: Calling variable from array? -
how call variable array? trying make this:
hello_world = "hey" array = [ '#{hello_world} ho' ] array.each |a| puts end
say ["hey ho"]
instead of ["\#{hello_world} ho"]
.
do below -
hello_world = "hey" array = [ "#{hello_world} ho" ] array # => ["hey ho"] array.each |a| p end # >> "hey ho"
single-quoted strings disabling interpolation, double-quote strings allow interpolation.
remember - interpolation may disabled escaping “#”
character or using single-quote strings:
'#{1 + 1}' #=> "\#{1 + 1}"
Comments
Post a Comment