-2

I have the following array

a = []

When I call a.empty? It will return true. But I want the same result in Numeric that is 1(In ruby 1 means true and 0 means false).

I know one scenario by using ternary operator

a.empty? ? 1 : 0

I want the same result without using any operators or if else conditions.

2
  • your scenario is the simplest way Commented Dec 14, 2014 at 4:26
  • Also, just three days ago. Commented Dec 14, 2014 at 4:53

1 Answer 1

0

In ruby 1 means true and 0 means false

This is simply not true (pun intended). 0 is true as well as 1. Try it out.

The only falsy values in ruby are nil and false - that's it. So, an empty string is true, empty array is true, 0 is true etc.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.