I am confused with how puts _|_ works in Ruby. If you type in a variable and then call that statement
3
puts _|_
you get the name of the variable followed by nil
3
=> nil
However, if you type it again, you get false
puts _|_
=> false
It doesn't seem like one of those Perl-like variables that begin with a dollar sign.
What in the world does this weird symbol mean and how does it work?
The underscore in a console (IRB or pry) stands for the result of the previous command. So
3
=> 3
puts _|_
3
=> nil
Here the above puts statement becomes equivalent to
puts 3 <bit-wise or> 3
which puts 3|3 equals puts 3.
Since puts returns nil, when you repeat the puts _|_ it becomes
puts nil|nil
... which is puts false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With