# [Ruby] What is `!!` used for?

#### Introduction

It doesn't come out even if I go around ... There is a sense of discomfort in using Japanese that seems to be missing ...

I will write it with my own interpretation that I looked up and saw

#### `!` Is a logical operator

A logical operator is an operator that returns true or false.

Other logical operators include ʻand` and ʻor`

`!` Evaluates the object

Returns true if nil or false

Returns false if true

That is `!`

That is, the logical operator of negation

Example

irb(main):018:0> !nil => true irb(main):019:0> !false => true irb(main):020:0> !true => false

``````
#### ~~ `!!` is a negative logical operator of negation ~~

* @scivola commented that the single logical operator `!!` is not open. The above does not seem to be an appropriate expression, so I will correct it, thank you! *

#### What is `!!`

By repeating `!` Twice, the true or false returned by the first `!` Is denied once more.

Returns false if nil or false

Returns ture if true

In other words, you are denying denial.
> Example

>```
irb(main):025:0> !!false
=> false
irb(main):026:0> !!nil
=> false
irb(main):027:0> !!true
=> true
``````

Well, I don't know what it's used for.

Isn't it missing? Do you feel that you are using Japanese like this?

#### The answer is logical operators. Was that

Logical operators evaluate and return logical value objects (true, false)

Of course, the return values of all objects are not necessarily logical value objects.

``````irb(main):001:0> a = "Ah"
=> "Ah"
irb(main):002:0> a
=> "Ah"
``````

So, when you want true or false, if you write without using `!!`, it will look like this

``````irb(main):028:0> a = "Ah"
=> "Ah"
irb(main):029:0> a ? true : false
=> true
``````

But if you use `!!`

``````irb(main):031:0> a = "Ah"
=> "Ah"
irb(main):032:0> !!a
=> true
``````

With this, you can call with two letters! Amazing smart! !!

This was my merit ~ That's it!