[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

is a "?" at end of method name only for boolean result?

Greg Hauptmann

11/5/2008 10:43:00 PM

when should I use ? at the end of a method name?. for queries that
return (a) boolean value, or (b) any return values? ie any method that
returns data

Thanks

--
Sent from my mobile device

3 Answers

Tim Hunter

11/5/2008 11:33:00 PM

0

Greg Hauptmann wrote:
> when should I use ? at the end of a method name?. for queries that
> return (a) boolean value, or (b) any return values? ie any method that
> returns data
>
> Thanks
>

By convention the ? suffix is reserved for methods that return a boolean
value. Note that all methods return some value, even if it's just nil.

--
RMagick: http://rmagick.ruby...

Ken Bloom

11/6/2008 12:20:00 AM

0

On Wed, 05 Nov 2008 18:32:41 -0500, Tim Hunter wrote:

> Greg Hauptmann wrote:
>> when should I use ? at the end of a method name?. for queries that
>> return (a) boolean value, or (b) any return values? ie any method that
>> returns data
>>
>> Thanks
>>
>>
> By convention the ? suffix is reserved for methods that return a boolean
> value. Note that all methods return some value, even if it's just nil.

The defined? operater breaks that convention. It returns nil if the name
it's given is undefined, but a string indicating what kind of object it
is if the name is defined. So you could say the ? suffix is intended for
methods whose outputs are usually treated as boolean.

--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...

Michael Morin

11/7/2008 4:39:00 AM

0

Greg Hauptmann wrote:
> when should I use ? at the end of a method name?. for queries that
> return (a) boolean value, or (b) any return values? ie any method that
> returns data
>
> Thanks
>

Is the method asking a question or query? By the convention, the method
should has a question or query (some_thread.alive? or
some_string.empty?) and it should work in an if statement. This is only
a convention though, but it could be a little confusing if bend the
rules a little.