Skip to content
This repository has been archived by the owner on Aug 28, 2019. It is now read-only.

Ruby string interpolation document. #4162

Merged
merged 1 commit into from
Jul 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/pages/ruby/ruby-string-interpolation/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Ruby String Interpolation
---

# String Interpolation

String interpolation provides a more readable and concise syntax for building strings. You may be familiar with concatenation via the `+` or `<<` methods:

```ruby
"Hello " + "World!" #=> Hello World
"Hello " << "World!" #=> Hello World
```

String interpolation provides a way to embed Ruby code directly into a string:

```ruby
place = "World"
"Hello #{place}!" #=> Hello World!

"4 + 4 is #{4 + 4}" #=> 4 + 4 is 8
```

Everything between `#{` and `}` is evaluated as Ruby code. In order to do so, the string must be surrounded by double quotes (`"`).

Single quotes will return the exact string inside the quotes:

```ruby
place = "World"
'Hello #{place}!' #=> Hello #{place}!
```