2
我正在查看Ruby 1.9中用Ruby 1.8编写的一些代码,现在在1.9.2中运行它时会引发错误。这种方法强制将字符串强制转换为Fixnum
def encrypt(s)
return process(s) {|c, key| 64 + mod(c + key - 128)}
end
给我下面的错误
in `+': String can't be coerced into Fixnum (TypeError)
这里是我的代码:
def mod(c)
return c - 26 if c > 26
return c + 26 if c < 1
return c
end
def process(s, &combiner)
s = sanitize(s)
out = ""
s.each_byte { |c|
if c >= 'A'.ord and c <= 'Z'.ord
key = @keystream.get
res = combiner.call(c, key[0])
out << res.chr
else
out << c.chr
end
}
return out
end
查找函数'mod',我不确定它是新的'modulo'函数还是自定义的? – Candide
@Candide发布了mod函数 – BrainLikeADullPencil
还显示了进程函数 –