# Ruby 小知識04:插值 (Interpolation) ###### tags: `Ruby` `AstroCamp` Interpolation 的中文是插值的意思,顧名思義就是可以在字串當中插入某個值。在Ruby 當中以 #{ } 來表示 來看個例子吧! ``` card = "blue_eyes_white_dragon" puts "I summon #{card} \!" #=> I summon blue_eyes_white_dragon ``` 就是這樣的效果 *** 要注意如果用的是小括號或者是小寫%q,插值沒有辦法作用,就沒辦法印出帶入變數的參數 ``` card = "blue_eyes_white_dragon" %Q(I summon #{card} \!) #=> "I summon blue_eyes_white_dragon !" %q(I summon #{card} \!) #=> "I summon \#{card} \\!" %W[Yu_gi #{card} Kaiba] #=> ["Yu_gi", "blue_eyes_white_dragon", "Kaiba"] %w[Yu_gi #{card} Kaiba] #=> ["Yu_gi", "\#{card}", "Kaiba"] ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up