How do I call a variable from an array? Trying to make this:
hello_world = "Hey"
array = [ '#{hello_world} ho' ]
array.each do |a|
puts a
end
say ["Hey ho"] instead of ["\#{hello_world} ho"].
How do I call a variable from an array? Trying to make this:
hello_world = "Hey"
array = [ '#{hello_world} ho' ]
array.each do |a|
puts a
end
say ["Hey ho"] instead of ["\#{hello_world} ho"].
Do as below -
hello_world = "Hey"
array = [ "#{hello_world} ho" ]
array # => ["Hey ho"]
array.each do |a|
p a
end
# >> "Hey ho"
Single-quoted strings disabling interpolation, but double-quote strings allow interpolation.
Remember - Interpolation may be disabled by escaping the “#” character or using single-quote strings:
'#{1 + 1}' #=> "\#{1 + 1}"