這裏是什麼,我試圖做一個例子:有沒有辦法在Ruby中使用整數作爲方法名?
def 9()
run_playback_command(NINE_COMMAND)
end
我喜歡這種方式,因爲它應該是這個樣子以後使用:
if(channelNumber != nil)
splitChannel = "#{channelNumber}".split(//)
if(splitChannel[3] != nil)
response = "#{splitChannel[3]}"()
end
if(splitChannel[2] != nil)
response = "#{splitChannel[2]}"()
end
if(splitChannel[1] != nil)
response = "#{splitChannel[1]}"()
end
if(splitChannel[0] != nil)
response = "#{splitChannel[0]}"()
end
end
很抱歉的麻煩,如果這是一個簡單的問題!我對Ruby很新。
編輯:
這裏就是我試圖讓Siri的做:
if(phrase.match(/(switch to |go to)channel (.+)\s (on)?(the)?(directv|direct tv)(dvr| receiver)?/i))
self.plugin_manager.block_rest_of_session_from_server
response = nil
if(phrase.match(/channel \s([0-9]+|zero|one|two|three|four|five|six|seven|eight|nine)/))
channelNumber = $1
if(channelNumber.to_i == 0)
channelNumber = map_siri_numbers_to_int(channelNumber)
end
channelNumber.to_s.each_char{ |c| run_playback_command(COMMAND[c]) }
end
難怪它不是讀取通道。幫幫我?
我這樣讀了3次,仍然不確定你想要做什麼。您不能將9定義爲方法,請解釋9與代碼片段的關係。 – Gazler
我正在嘗試爲SiriProxy製作DirecTV頻道轉換器。問題是,您必須將按鈕逐個發送到接收器。在底部的代碼片段中,它將信道分離並將數字發送到定義,然後運行該命令。 – williammck