Created
January 29, 2016 23:37
-
-
Save Supernats/5c96e1b9409638161a68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module StringAppleization | |
| refine String do | |
| def appleize | |
| split(' ').map do |word| | |
| appleize_word(word) | |
| end.join(' ') | |
| end | |
| private | |
| def appleize_word(word) | |
| first_letter = word[0] | |
| rest = word[1..-1] | |
| case first_letter | |
| when 'i' | |
| first_letter + rest.capitalize | |
| when 'I' | |
| first_letter.downcase + rest.capitalize | |
| else | |
| word.capitalize | |
| end | |
| end | |
| end | |
| end | |
| class AppleizedSentence | |
| using StringAppleization | |
| def initialize(sentence) | |
| @sentence = sentence | |
| end | |
| def i_sentence | |
| sentence.appleize | |
| end | |
| private | |
| attr_reader :sentence | |
| end | |
| puts AppleizedSentence.new("this iphone is awesome").i_sentence |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment