Last active
March 26, 2016 06:47
-
-
Save katsuhide/6959795 to your computer and use it in GitHub Desktop.
文字列周り
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 文字列中に変数を指定する | |
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