Best way to switch values

Mitja Čebokli

I would like to find the most effective and short way to do the following:

if current_value == "hide"
  current_value   = "show"
elsif current_value == "show"
 current_value     = "hide"
end

So, i would like to set the opposite to what the current situation is.

Thanks!

ant

What about ternary?

current_value == "hide" ? current_value = "show" : current_value = "hide"

Maybe this would be better :

current_value = (current_value == "hide") ? "show" : "hide"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Java compare values, best way

From Dev

What is the best way to switch between projects in Vim?

From Dev

Best way to switch between two fragments

From Dev

Best way to provide static (default) values

From Dev

Best way to update several values in hashmap?

From Dev

Best way to store bunch of constant values in .NET

From Dev

Best way to replace missing/undefined values in an array?

From Dev

Best way to override module values/constants in angularJS

From Dev

Best way to reset all values in an Javascript object

From Dev

C Best way of modifying values in a function

From Dev

Best way to hide values for sessionState provider

From Dev

Best way to get values using ngFormController

From Dev

Best way to force values to uppercase in sqlalchemy field

From Dev

Best way to assign values of an array to a struct

From Dev

Best way to add values to an object?

From Dev

Redis: the best way to get all hash values

From Dev

Best way to swap variable values in Go?

From Dev

Java compare values, best way

From Dev

mysql - best way to store multiple values

From Dev

Ruby best way to sum diagonal values of a matrix

From Dev

Best way to replace values in XML content?

From Dev

Best way to store multi-values in a field

From Dev

Best way to store bunch of constant values in .NET

From Dev

best way to pass core data values

From Dev

Oracle: best way to deal with NULL values

From Dev

Best way to get values using ngFormController

From Dev

Best way to use a:hover to switch images in HTML?

From Dev

Best way to concatenate column values in aggregate

From Dev

Best way to switch elements in pom.xml