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
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.
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.
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.