Forum: Ruby Re: boolean affectation shortcut

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peña, Botp (Guest)
on 2006-05-13 14:09
(Received via mailing list)
fr 13:
# You can' t because only methods can end with ?

i think he is asking, why not? of course, we know it is not currently
possible, but variable names with "?" may enhance readability.

consider,

x? = method_that_determines_some_status

....

if x?
  ....

end

by just looking at the name, we are pretty sure that x? is a boolean
(just like is_xx? methods return bools).

wc is better than,

if x
   ...
end

whether x is a variable or method..

it's just an added character where one may happily use or not. But maybe
i am missing something deeper..

kind regards -botp
This topic is locked and can not be replied to.