Skip to content

Instantly share code, notes, and snippets.

@VictorTpo
Last active May 2, 2016 13:05
Show Gist options
  • Save VictorTpo/4ee20fe22846339f4b3cb4cd17f542d4 to your computer and use it in GitHub Desktop.
Save VictorTpo/4ee20fe22846339f4b3cb4cd17f542d4 to your computer and use it in GitHub Desktop.
def genderize(word_m, subject, word_f = nil)
  return word_m if male?(subject)
  return word_f if word_f.present?
  word_m + 'e'
end
private
def male?(subject)
  subject.gender.casecmp('male') == 0
end

Documentation

"abcdef".casecmp("abcde")     # => 1
"aBcDeF".casecmp("abcdef")    # => 0
"abcdef".casecmp("abcdefg")   # => -1
"abcdef".casecmp("ABCDEF")    # => 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment