Skip to content

Instantly share code, notes, and snippets.

@maasha
Last active May 21, 2021 11:18
Show Gist options
  • Save maasha/27a14fd89a9f03c031d2a9723464f6dc to your computer and use it in GitHub Desktop.
Save maasha/27a14fd89a9f03c031d2a9723464f6dc to your computer and use it in GitHub Desktop.
golf me
def camel_case_to_title(str)
return 'eClass' if str == 'e_class'
return 'ID' if str == 'id'
word_parts = []
str.split('_').each do |word|
word_parts << word.capitalize unless word == 'id'
end
word_parts.join(' ')
end
@adam12
Copy link

adam12 commented May 21, 2021

def camel_case_to_title(str)
  return "eClass" if str == "e_class"
  return "ID" if str == "id"

  str.split("_").filter_map { |word| word.capitalize unless word == "id" }.join(" ")
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment