You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# The conditional assignment operator `||=` is used to assign a value to a variable only if the variable is currently `nil` or `false`.
# This can be useful for setting default values or initializing variables.
# Example usage:
name = nil
name ||= "Guest"
puts name # Output: Guest
age = 25
age ||= 30
puts age # Output: 25
is_active = false
is_active ||= 'ok'
puts is_active # Output: 'ok'
# In the first example, since `name` is `nil`, it gets assigned the value "Guest". In the second example, since `age` already has a value (25), it does not get reassigned to 30.
# The conditional assignment operator is a shorthand for the following code:
name = name || "Guest"
age = age || 30
# You can read the official docs for more details.