Project

General

Profile

Actions

Feature #12012

closed

Add Boolean method

Added by ka8725 (Andrey Koleshko) almost 9 years ago. Updated about 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:73020]

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?


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #11848: New #to_b method for String, Symbol, Numeric, NilClass, TrueClass and FalseClass.Rejectedmatz (Yukihiro Matsumoto)Actions

Updated by nobu (Nobuyoshi Nakada) almost 9 years ago

  • Status changed from Open to Feedback

For what purpose?

Updated by marcandre (Marc-Andre Lafortune) almost 9 years ago

  • Status changed from Feedback to Rejected

Please see discussion for #11848.

Updated by phluid61 (Matthew Kerwin) almost 9 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) almost 9 years ago

Unsubscribe:
http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core

On 21/01/2016 8:38 PM, 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.

Actions #5

Updated by naruse (Yui NARUSE) almost 9 years ago

  • Is duplicate of Feature #11848: New #to_b method for String, Symbol, Numeric, NilClass, TrueClass and FalseClass. added

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

On 2016/10/28 11:57, RRRoy BBBean wrote:

irb(main):002:0> !!('hi')
(irb):2: warning: string literal in condition
=> true

Why 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) about 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
=> true

Why 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?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0