Return the opposite of two known strings given one 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" =&gt; "reading",  "reading" =&gt; "maths"}[subscription_type]
end


Can anyone top that?
Your first two solutions both suffer when given unexpected input.  The first is biased towards returning "maths" as a default; the second tends to return "reading".

In contrast, your colleague's function returns nil, which is probably more appropriate.  I quite like that straightforward lookup, with a minor drawback being that each string is hard-coded twice.

Here's one more suggestion.  This one crashes with TypeError: nil can't be coerced into Fixnum when given invalid input.  You should decide whether that exception is beneficial or not for your purpose.

SUBJECTS = %w(reading maths)

def matching_sub(subscription_type)
  SUBJECTS[1 - SUBJECTS.index(subscription_type)]
end