Ruby代码美化,将长指令拆分成多行 [英] Ruby code beautification, split long instructions on multiple lines

查看:86
本文介绍了Ruby代码美化,将长指令拆分成多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何编写以下语句来提高可读性?

How can we write the following statement to improve readability?

Promotion.joins(:category).where(["lft>=? and rgt<=?", c.lft, c.rgt]).joins(:shops).where(:promotions_per_shops => { :shop_id => shops_id }).count('id', :distinct => true)

以下内容无法编译

Promotion.joins(:category)
         .where(["lft>=? and rgt<=?", c.lft, c.rgt])
         .joins(:shops)
         .where(:promotions_per_shops => { :shop_id => shops_id })
         .count('id', :distinct => true)

syntax error, unexpected '.', expecting kEND
                     .where(["lft>=? and rgt<=?", c.lft, c.rgt])


推荐答案

这样做:

Promotion.joins(:category).
         where(["lft>=? and rgt<=?", c.lft, c.rgt]).
         joins(:shops).
         where(:promotions_per_shops => { :shop_id => shops_id }).
         count('id', :distinct => true)

这篇关于Ruby代码美化,将长指令拆分成多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆