In kotlin and C#, you can assign a variable, or else if the value is nil, you can throw an exception using the ?:
and ??
operators.
For example, in C#:
var targetUrl = GetA() ?? throw new Exception("Missing A");
// alt
var targetUrl = GetA() ?? GetB() ?? throw new Exception("Missing A or B");
Is this possible in ruby? If so, how?
Basically, what I want to do is this
target_url = @maybe_a || @maybe_b || raise "either a or b must be assigned"
I'm aware I can do this
target_url = @maybe_a || @maybe_b
raise "either a or b must be assigned" unless target_url
but I'd like to do it in a single line if possible