Issue #12012 has been updated by Matthew Kerwin.


(Sorry, I replied by email but the message doesn't show on the bugs.ruby-lang.org tracker)

Andrey Koleshko wrote:
> 
> What do you think, guys, about this suggestion?

There is a real risk inherent in mixing natural truthiness (`!!foo`) and an arbitrary definition of what we may consider "usefully true".

Compare your set of truthy-y values to mine here: https://github.com/phluid61/mug/blob/master/lib/mug/bool.rb

It definitely needs a strong, consistent rationale to describe what is truthy-y and what isn't. In my case, testing for zero, blank, and empty were useful for me, so I created my #to_b to do that.

----------------------------------------
Feature #12012: Add Boolean method
https://bugs.ruby-lang.org/issues/12012#change-56298

* Author: Andrey Koleshko
* Status: Rejected
* Priority: Normal
* Assignee: 
----------------------------------------
In Ruby we have methods with a capital letter which are used for implicit type casting. For example: `Array`, `String`, `Integer` and etc. But there is lack of one desired function that I recently define in all my projects - this is `Boolean`. I mean it would be great to have in Ruby the built-in function:

~~~
Boolean(nil) # => false
Boolean("") # => true - I'm not sure about this. It's more convenient to have false here
Boolean("false") # => true
Boolean("0") # => false
Boolean("1") # => false
Boolean("test") # => true
~~~

What do you think, guys, about this suggestion?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>