工程师的自我修养

来源:互联网 发布:彩视官网 软件 编辑:程序博客网 时间:2024/04/28 02:54

背景

要根据scope来设置一个class

我写的

if current_path.split('?')[0] == tags_console_tickets_path  klass = scope == "tags_all" ? "current" : nilelse  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" : nilend

老大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