0

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"].

1
  • It has nothing to do with array. Commented Jun 8, 2014 at 9:23

1 Answer 1

4

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}" 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.