新手问题 如何精简这个 collection 里面的 if else

luffycn · December 09, 2014 · Last by huhongda replied at December 09, 2014 · 1252 hits


list.map do |t|
  t = t.search('a')
  if  block
    'xxx'
   else
     'yyy'
   end

end

里面这个 if else 有没办法弄得好看点

list.map do |t|
  t = t.search('a')
  block ? 'xxx' : 'yyyy'
end

如果没有别的代码,我就同上,但是我猜想里面应该不止一行代码吧!你得把具体的代码贴出来~

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