3 ms·
Yes, definitely omit parentheses when calling a method without arguments. For calls with some non-block arguments, it's not so clear-cut as "always include par
by epidemian 3y ago
Yes, definitely omit parentheses when calling a method without arguments.
For calls with some non-block arguments, it's not so clear-cut as "always include parentheses".
Some methods are so prevalent that they almost become part of the language "syntax", even though there's nothing syntactically special about them. For example, you rarely see parentheses used on calls to `attr_accessor` or `private`:
class Cat
attr_accessor :fluffiness
private def plan_world_domination
# TODO
end
end
I think parentheses around `private(def some_method ... end)` would be especially non-idiomatic. Even though passing the result of the `def` expression to the `private` method is exactly what's happening.
Another place where it's usual to omit method call parentheses is on embedded DSLs. For example, in RSpec it's uncommon to include parentheses on calls to `describe` or `it`.
describe "RSpec DSL" do
it "looks neater without parentheses" do
# ...
end
end
- weaksauce 3y agoyeah there will always be edge cases but those are few and why i hedged with gravitate toward. private feels like a part of the language actually like an if statement instead of a method though.