This is probably silly, but I feel like there should be a much more elegant way to do this simple thing. I have two known strings, whichever one is passed in in the parameter I want to return the opposite. Current code:
def matching_sub(subscription_type)
if subscription_type == "maths"
"reading"
else
"maths"
end
end
I came up with:
def matching_sub(subscription_type)
(%w{reading maths} - [subscription_type]).first
end
and my colleague did:
def matching_sub(subscription_type)
{"maths" => "reading", "reading" => "maths"}[subscription_type]
end
Can anyone top that?
subscription_type == "maths" ? "reading" : "maths"
and be done with it... \$\endgroup\$