From: Alex Young Date: 2012-03-21T19:49:18+09:00 Subject: [ruby-core:43524] Re: [ruby-trunk - Feature #6180] to_b for converting objects to a boolean value On 21/03/12 01:44, trans (Thomas Sawyer) wrote: > > Issue #6180 has been updated by trans (Thomas Sawyer). > > > Also, what you are asking for should probably be called #to_bool. > > Where as #to_b can have a broader, and generally more useful definition, e.g. > > "true".to_b #=> true > "yes".to_b #=> true > "on".to_b #=> true > > 1.to_b #=> true > 0.to_b #=> false > > and other such useful humanistic forms of expressing truth. > This would be most useful as a protocol for `if` statements so that classes could define their own notion of falsity. This is not dissimilar to my null proposal from a few months back. -- Alex > > ---------------------------------------- > Feature #6180: to_b for converting objects to a boolean value > https://bugs.ruby-lang.org/issues/6180#change-24992 > > Author: AaronLasseigne (Aaron Lasseigne) > Status: Open > Priority: Normal > Assignee: > Category: > Target version: > > > When a boolean return value is required it has become common practice is to use "!!" to convert the object. It would be more consistent to provide a "to_b" method on Object. > >