In Ruby, you can simply negate an expression by using "!"
abc = 'abc' !abc #=> false
Similarly,
abc = 'abc' !abc #=> false !!abc #=> true
Ruby's double-bang negates the negated statement, which almost always will give you true.
a = 0 b = 1 c = true d = false !a #=> false !!a #=> true !b #=> false !!b #=> true !c #=> false !!c #=> true !d #=> true !!d #=> false
So be careful using the double bang to test for truth. Better test with positive equality in your conditions over using the double bang.
Tags:
technology, ruby
Author
Maricris Nonato
I turn tech ideas into websites using Ruby. I'm a budding Buddhist practitioner, passionate about health & fitness, a licensed yoga teacher (RYT 200), and a cat fanatic!
Recent posts
Tags
- cats
- yoga
- blood pressure
- elecom
- scrum
- coderkitty
- RailsGirls
- workstation
- creativity
- live book signing
- healthy living
- lowering blood pressure
- crafting
- movies
- reviews
- new year
- blessings
- faith
- quotes to live by
- travelers notebook
- Bujo
- planners
- Monday Motivation
- himalayan salt lamp
- productivity
- life tips
- happiness
- success
- ruby
- digital ocean
- regex
- programming
- humor
- music
- pyromusical
- sphinx
- mac
- games
- musings
- yogi
- namaste
- photography
- hobby
- slimming
- sendmail
- lifestyle
- memes
- open letter
- sports
- shooting
- events
- meetups
- tech talks
- rails
- datatables
- sorting
- cycling
- COVID-19
- wishlist
- xmas
- tradition
- song lyrics
- life lessons
- poems
- short story
- food
- living life
- nginx
- technology
- youtube
- my Nyey
- meditation
- new normal
- jump rope
- two-wheel journey
- planner girl
- rubyist
- culture
- Filipino
Advertise
Advertise here