我反复使用Twilio Say动词并想重构我的代码。目前看起来有点像这样
def sample
render text: (Twilio::TwiML::Response.new do |r|
r.Say 'Welcome to ABC Residence', voice: 'alice', language: 'en-GB'
r.Say 'Thank you for visiting ABC Residence.', voice:'alice', language: 'en-GB'
r.Hangup
end).text
end
注意我正在使用voice: 'alice'
和language: 'en-GB'
两次。如何将这些变量放入变量中以便反复使用?
答案 0 :(得分:5)
将它们放入哈希并使用它:
def sample
props = {voice: 'alice', language: 'en-GB'}
render text: (Twilio::TwiML::Response.new do |r|
r.Say 'Welcome to ABC Residence', props
r.Say 'Thank you for visiting ABC Residence.', props
r.Hangup
end).text
end