変数に文字列を入れ込む
Ruby初心者のメモ書きです。
qiita.rb
name = "田中"
name2 = "斎藤"
puts "こんにちは、#{name}さん!"
puts 'こんにちは、#{name2}さん!'
#結果
こんにちは、田中さん!
こんにちは、#{name}さん!
シングルクオートで囲むと、変数は展開されずにそのまま出力される!!
Go to list of users who liked
More than 5 years have passed since last update.
Ruby初心者のメモ書きです。
name = "田中"
name2 = "斎藤"
puts "こんにちは、#{name}さん!"
puts 'こんにちは、#{name2}さん!'
#結果
こんにちは、田中さん!
こんにちは、#{name}さん!
シングルクオートで囲むと、変数は展開されずにそのまま出力される!!
Register as a new user and use Qiita more conveniently
Go to list of users who liked