Todd Benson
2/17/2008 10:21:00 AM
On Feb 17, 2008 4:16 AM, Todd Benson <caduceass@gmail.com> wrote:
>
> On Feb 16, 2008 12:04 PM, Michael Brooks <michael.brooks@shaw.ca> wrote:
> > Hello everyone:
> >
> > Why can't I name boolean variables with a "?" on the end? The "?" can
> > be used on the end of methods but not variable. Here is an example:
> >
> > # This naming convention works with "?"
> > def boolean_method?
> > return true
> > end
> > puts boolean_method?
> >
> > # This naming convention doesn't works with "?"
> > boolean_variable? = true
> > puts boolean_variable?
> >
> > The question mark would make the intention of the variable obvious, just
> > like it helps the method name.
> >
> > So why isn't this allowed? Did I miss something?
>
> I suppose because any object is true and the following wouldn't make sense...
>
> boolean_variable? = "false"
>
> You want to 'type' a variable (the syntax defines its purpose), which
> goes against the general grain of Ruby.
I guess that didn't really come out right. What you suggest is to
require variables of certain spelling to have a defined type
(boolean). Convention is fine for methods, but for variables, I think
it should be loose.
Todd