A method name can end with a question mark ?
def has_completed? return count > 10 end
but a variable name cannot.
What is the reason for that? Isn't it convenient to have variable names ending the same way too? Given that we usually can't tell whether foobar
is a method or a variable just by looking at the name foobar
anyway, why the exception for the ?
case?
And how should I work with this? Maybe always to use has
or is
in the code?
if process_has_completed ... end if user_is_using_console ... end
Yes it's fine, mainly because, syntactically , they're used differently.
In a word, yes. Variable names only hold in the scope they're defined in, and you can use the same name in different scopes.
Reserved keywords cannot be used as variable names. Reserved keywords are ALL, AND, BY, EQ, GE, GT, LE, LT, NE, NOT, OR, TO, and WITH. Variable names can be defined with any mixture of uppercase and lowercase characters, and case is preserved for display purposes.
Yes, It is allowed to define a method with the same name as that of a class.
You'd have to ask Matz to get an authoritative answer. However,
finished?
would imply a specific type (boolean) which appears somewhat contradictory to me.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With