Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Basics (Retired) Ruby Strings What are Strings?

3 Answers

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey there Yi,

#{} is used to interpolate a variable inside of a string in Ruby which means that you can use a variable inside of a string. To interpolate a variable inside of a string you have to write the variable name inside of the curly braces.

This would be an example:

name = "Yi"
puts "Hello, #{name}"

This would have the output "Hello, Yi".

I hope that helps, if not or if you have further questions feel free to ask! :)

jason chan
jason chan
31,009 Points

it's just another way to call a variable when printing.

Pretend variables are like batteries and then you want to use those batteries later in a sentence. In this case print as Tobias says.

rowend rowend
rowend rowend
2,926 Points

That is the way ruby evaluates expressions, convert them to string and place them into string. What I mean with expressions are not only variables, you can do math and other stuff.

Example:

name = 'rowend'
puts "my name is #{name} and my lucky number is #{12 + 9} and this is another string #{'my string'}"