stevec
stevec

Reputation: 52248

Which ruby methods/keywords behave differently depending on whether parentheses are used?

I thought it was kinda cool that super and super() offer different behaviours, with the latter calling the parent method without passing it arguments.

This is the first case I'm aware of of a ruby method/keyword that behaves differently depending on whether the () are included (more on that here).

Are there any other methods/keywords in the ruby programming language which exhibit different behaviour depending on whether the () are included?

Upvotes: 1

Views: 97

Answers (2)

eva
eva

Reputation: 73

Methods in Ruby behave same whether you use parenthesis or not. According to the Ruby style guide, you can omit parenthesis after a method call when you don't pass any arguments. It's true that some Ruby programmers liberally omit parenthesis but this will not make their methods behave differently.

Upvotes: 1

Jörg W Mittag
Jörg W Mittag

Reputation: 369428

It is impossible for a Ruby method to know what syntax was used for the message send, therefore, a method cannot possibly behave different depending on whether or not the message send includes ().

Upvotes: 2

Related Questions