LoginSignup
0
0

More than 3 years have passed since last update.

ruby 文字列オブジェクトについて

Last updated at Posted at 2019-10-31

文字列概要

  • "" 特殊文字使える、式展開
  • \n⇒改行
  • \t⇒タブ挿入
puts "hello world"

実行結果:hello world

puts "he\nllo wor\tld"

実行結果:
he
llo wor ld

  • '(シングルクォーテーション)では特殊文字を使用することはできない
puts 'he\nllo wor\tld'

実行結果:he\nllo wor\tld

文字列の式展開

puts "price #{3000 * 4}"
puts 'price #{3000 * 4}'

実行結果:
price 12000
price #{3000 * 4}

name = "My friends"
puts "hello #{name}"

実行結果:hello My friends

puts "hello" + "world"
puts "hello" * 5

実行結果:
hello world
hellohellohellohellohello

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0