Skip to content

Instantly share code, notes, and snippets.

@katsuhide
Last active March 26, 2016 06:47
Show Gist options
  • Save katsuhide/6959795 to your computer and use it in GitHub Desktop.
Save katsuhide/6959795 to your computer and use it in GitHub Desktop.
文字列周り
# 文字列中に変数を指定する
a = "hoge"
b = "fuga"
puts "#{a}と#{b}はほげふがです"
# 置換
s = "Apple Banana Apple Orange"
p s.sub("Apple", "Pine") #=> "Pine Banana Apple Orange"
p s.gsub("Apple", "Pine") #=> "Pine Banana Pine Orange"
# 数字を文字列に
num = 11111
puts num.to_s
# 文字列の連結
str1 = "hoge"
str2 = "fuga"
puts str1 + str2
num = 11111
puts str1 + num.to_s
# ヒアドキュメント
## ""囲みとして扱う
<<-"EOS"
<<- のようにマイナス記号を付加すると
終了ラベルをインデントしてもおkになる
細かいことだけどこれは#{word}重要
EOS
## ''囲みとして扱う
<<'EOS'
識別子は任意です
EOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment