我發現了一個使用此函數的ruby加密庫。Ruby 1.9.x未定義的方法^用於字符串
def process(text)
0.upto(text.length-1) {|i| text[i] = text[i]^round}
text
end
在紅寶石1.9.x的
它拋出一個錯誤 - undefined method ^' for "\x1A":String__
有沒有變通的方法在紅寶石1.9.x的?
谷歌搜索後,我才知道「在Ruby 1.9中string [index]返回字符而不是字符的代碼(就像它在1.8中)」(https://rails.lighthouseapp.com/projects/ 8994 /票/ 3144-未定義法換串ROR-234)
在此先感謝
`text.each_byte.map {| b | (B ^圓).CHR} .join` – levinalex 2011-09-04 13:29:53