Feature #12012
closedAdd Boolean method
Description
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?
Updated by nobu (Nobuyoshi Nakada) over 8 years ago
- Status changed from Open to Feedback
For what purpose?
Updated by marcandre (Marc-Andre Lafortune) over 8 years ago
- Status changed from Feedback to Rejected
Please see discussion for #11848.
Updated by phluid61 (Matthew Kerwin) over 8 years ago
(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.
Updated by phluid61 (Matthew Kerwin) over 8 years ago
Unsubscribe: mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe
http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core
On 21/01/2016 8:38 PM, ka8725@gmail.com 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 defitinitely 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.
Updated by naruse (Yui NARUSE) over 8 years ago
- Is duplicate of Feature #11848: New #to_b method for String, Symbol, Numeric, NilClass, TrueClass and FalseClass. added
Updated by prodis (Fernando Hamasaki de Amorim) almost 8 years ago
You can use wannabe_bool
gem: https://github.com/prodis/wannabe_bool
Updated by nobu (Nobuyoshi Nakada) almost 8 years ago
On 2016/10/28 11:57, RRRoy BBBean wrote:
irb(main):002:0> !!('hi')
(irb):2: warning: string literal in condition
=> trueWhy do I get this warning? Shouldn't I be able to use bang-bang to convert anything to it's corresponding Boolean value?
Please file a new ticket to report a bug.
BTW, why doesn't Mail_to_issue work?
Updated by rrroybbbean (RRRoy BBBean) almost 8 years ago
I'm doing a bug report now.
I use Thunderbird, and I didn't know whether to use Reply or Reply to
Group. Sorry.
On 10/28/2016 02:56 AM, Nobuyoshi Nakada wrote:
On 2016/10/28 11:57, RRRoy BBBean wrote:
irb(main):002:0> !!('hi')
(irb):2: warning: string literal in condition
=> trueWhy do I get this warning? Shouldn't I be able to use bang-bang to convert anything to it's corresponding Boolean value?
Please file a new ticket to report a bug.BTW, why doesn't Mail_to_issue work?