** Expression expansion is a feature that allows you to put an expression inside a string. ** **
** To write the expression expansion, just write # {expression} </ font> in the string. ** **
** When expanding expressions, double quotation marks "</ font> when creating a string Must be enclosed in. ** ** ** If you enclose it in single quotation marks' </ font>, the expression will not be expanded. ** **
Let's try expression expansion.
irb
#Expression expansion includes an expression in a string
irb(main):001:0> "Today#{20}I'm old"
=> "I'm 20 years old today"
#Expression is not expanded with single quotes
irb(main):002:0> 'Today#{20}I'm old'
=> "Today\#{20}I'm old"
** Expressions are "character strings", "numbers", "variables", "operator expressions", etc. in Ruby. Expression expansion is a function that allows you to put an expression in a character string. ** **
Recommended Posts