好吧,我是 ruby 新手,我有这个 ID 生成器,它根据 Time.now.to_f/time.time() 生成一个 ID,然后是一个 8 长度的 id,例如这是工作的 python 版本
def anonId(a,b):
a = a.split('.')[0]
if len(a) > 4: i = a[6:]
else: i = a
return "".join(str(int(x) + int(y))[-1] for x, y in zip(i, b[4:]))
正在做
anonId("1379697991.99",'26002859')
会生成 '9740' 的 ID 在 ruby 中我已经尝试过这样的事情,但我不太了解 ruby 还不知道该怎么做,但这是我到目前为止所拥有的
def anonId(number,id)
if String(number).length > 4 then number = String(number).split(".")[0][-4..-1] else number end
[number,id[4..-1]].zip.each do |x,y|
#this is where I get stuck at, I'm not sure if the above is correct
end
end
所以基本上,我需要知道如何将 python 代码转换为 ruby