Ruby函数调用的括号的主导风格是什么? [英] What is the dominant style for parenthesization of Ruby function calls?

查看:234
本文介绍了Ruby函数调用的括号的主导风格是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有 func_a func_b 这两个都有一个参数,我想传递 func_b func_a



括号括起来?


  1. func_a func_b input

  2. func_a func_b(input)

  3. func_a(func_b input)

  4. func_a(func_b(input))


解决方案

您必须扫描来源才能找到最常见的。



感觉,但几乎总是使用:

  func_a func_b(arg)
func_a(func_b ))

如果函数被命名为听起来像一个句子或短语

  func_a func_b arg 

换句话说,如果它听起来像我大声说出来的话,我会像我说的那样写一个句子或短语。 / p>

如果它听起来不像我在现实生活中说的那样,需要括号来提高清晰度,等等,然后我会写它像我写代码,因为它听起来像/看起来像代码。


Say I have func_a and func_b which both take one argument, and I want to pass the result of func_b to func_a.

What is the most common way to parenthesize this?

  1. func_a func_b input
  2. func_a func_b(input)
  3. func_a(func_b input)
  4. func_a(func_b(input))

解决方案

You'd have to scan source to find the "most common".

I try to write what makes sense under the circumstances, but would almost always use either:

func_a func_b(arg)
func_a(func_b(arg))

If the functions are named things that "sound like" a sentence or phrase, then I'll drop as many parens as I can.

func_a func_b arg

In other words, if it sounds like something I'd say out loud, I'll write it like I'd say it--a sentence or phrase.

If it doesn't sound like something I'd say in real life, needs parens to enhance clarity, etc. then I'll write it like I'm writing code, because it sounds/looks like code.

这篇关于Ruby函数调用的括号的主导风格是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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