工程师的自我修养

背景

要根据scope来设置一个class

我写的

if current_path.split('?')[0] == tags_console_tickets_path
  klass = scope == "tags_all" ? "current" : nil
else
  klass = ((params[:scope] and params[:scope] == scope.to_s) or (params[:scope].blank? and scope.to_s == "unclosed_and_assigned_me_and_last_replied_not_me")) ? "current" : nil
end

 
 
 

老大review后

 
klass = \
    if request.path == tags_consile_tickets_path
        "current" if scope.to_s == "tags_all"
    elsif params[:scope].present?
        "current" if params[:scope] == scope.to_s
    else
        "current" if scope.to_s == "unclosed_and_assigned_me_and_last_replied_not_me"
    end



然后我在来

 
klass = \
      if request.path == tags_console_tickets_path
        # tags_all
        "current" if scope == :tags_all
      elsif params[:scope].present?
        # status, assigner, tags etc..
        "current" if scope.to_s == params[:scope]
      end


老大批语

 
三元运算符是为了方便才存在的,写的跟看的人都不方便,就不要用了

我的感受

这里本来就写的比较复杂,然后我为了追求同样炫酷(主要是懒。。),稍微改改发现能用就扔那了。工程师的自我修养还是不到家。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值