Ruby eval 怎么返回多个值?

yakczh · January 11, 2015 · Last by lgn21st replied at January 11, 2015 · 1774 hits

str="bala bala   2015-01-20  balaba  12:14:36 +0800 "

code='''
date=''
time=''
  if str =~ /\d{4}-\d{2}-\d{2}/  then
    date=$&
   end
if str =~ /\d{2}:\d{2}:\d{2}/  then
    time=$&
   end

'''
result = eval(code)
puts result

我想获取 date 和 time 但是实际上只返回最后一个 time

返回一个数组,或者一个 Hash 吧。

You need to Sign in before reply, if you don't have an account, please Sign up first.