Post History
Omitting parens on function calls You can omit parentheses on function calls in many cases. foo(bar,baz) foo bar,baz This is even true if a function call doesn't have any parameters. (This is...
Answer
#3: Post edited
- # Omitting parens on function calls
- You can omit parentheses on function calls in many cases.
- ```ruby
- foo(bar,baz)
- foo bar,baz
- ```
- This is even true if a function call doesn't have any parameters. (This is because all function calls and property accesses are just methods, by the way.)
- ```ruby
- puts(gets())
- puts gets
- ```
- This can be especially convenient if a call chain can be rearranged so only the last function takes an argument.
- ```ruby
- ->{gets().split(",")}
- ->{gets.split ?,}
- ```
- Notably, you *can't* omit parens if you pass **an argument and a block** to a function.
- ```ruby
- a.reduce{_1+_2} # ok
- a.reduce(0){_1+_2} # ok
- a.reduce 0{_1+_2} # not ok
- ```
- # Omitting parens on function calls
- You can omit parentheses on function calls in many cases.
- ```ruby
- foo(bar,baz)
- foo bar,baz
- ```
- This is even true if a function call doesn't have any parameters. (This is because all function calls and property accesses are just methods, by the way.)
- ```ruby
- puts(gets())
- puts gets
- ```
- This can be especially convenient if a call chain can be rearranged so only the last function takes an argument.
- ```ruby
- ->{gets().split(",")}
- ->{gets.split ?,}
- ```
- You can even omit parens in a situation like this. Keep in mind this will become ambiguous in some cases!
- ```ruby
- puts rand 10 # ok
- print rand 10, " things" # bad! tries rand(10, " things")
- print rand(10), " things" # ok
- ```
- Notably, you *can't* omit parens if you pass **an argument and a block** to a function.
- ```ruby
- a.reduce{_1+_2} # ok
- a.reduce(0){_1+_2} # ok
- a.reduce 0{_1+_2} # not ok
- ```
#2: Post edited
- # Omitting parens on function calls
- You can omit parentheses on function calls in many cases.
- ```ruby
- foo(bar,baz)
- foo bar,baz
- ```
- This is even true if a function call doesn't have any parameters. (This is because all function calls and property accesses are just methods, by the way.)
- ```ruby
- puts(gets())
- puts gets
- ```
- This can be especially convenient if a call chain can be rearranged so only the last function takes an argument.
- ```ruby
- ->{gets().split(",")}
- ->{gets.split ?,}
- ```
- # Omitting parens on function calls
- You can omit parentheses on function calls in many cases.
- ```ruby
- foo(bar,baz)
- foo bar,baz
- ```
- This is even true if a function call doesn't have any parameters. (This is because all function calls and property accesses are just methods, by the way.)
- ```ruby
- puts(gets())
- puts gets
- ```
- This can be especially convenient if a call chain can be rearranged so only the last function takes an argument.
- ```ruby
- ->{gets().split(",")}
- ->{gets.split ?,}
- ```
- Notably, you *can't* omit parens if you pass **an argument and a block** to a function.
- ```ruby
- a.reduce{_1+_2} # ok
- a.reduce(0){_1+_2} # ok
- a.reduce 0{_1+_2} # not ok
- ```
#1: Initial revision
# Omitting parens on function calls You can omit parentheses on function calls in many cases. ```ruby foo(bar,baz) foo bar,baz ``` This is even true if a function call doesn't have any parameters. (This is because all function calls and property accesses are just methods, by the way.) ```ruby puts(gets()) puts gets ``` This can be especially convenient if a call chain can be rearranged so only the last function takes an argument. ```ruby ->{gets().split(",")} ->{gets.split ?,} ```