freeCodeCamp/guide/russian/ruby/ruby-string-interpolation/index.md

31 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Ruby String Interpolation
localeTitle: Интерполирование Ruby String
---
# Интерполяция строк
Строковая интерполяция обеспечивает более читаемый и сжатый синтаксис для построения строк. Вы можете быть знакомы с конкатенацией с помощью методов `+` или `<<` :
```ruby
"Hello " + "World!" #=> Hello World
"Hello " << "World!" #=> Hello World
```
Строковая интерполяция обеспечивает способ вставки кода Ruby непосредственно в строку:
```ruby
place = "World"
"Hello #{place}!" #=> Hello World!
"4 + 4 is #{4 + 4}" #=> 4 + 4 is 8
```
Все между `#{` и `}` оценивается как код Ruby. Для этого строка должна быть окружена двойными кавычками ( `"` ).
Одиночные кавычки вернут точную строку внутри кавычек:
```ruby
place = "World"
'Hello #{place}!' #=> Hello #{place}!
```