Skip to content

Instantly share code, notes, and snippets.

@Supernats
Created January 29, 2016 23:37
Show Gist options
  • Select an option

  • Save Supernats/5c96e1b9409638161a68 to your computer and use it in GitHub Desktop.

Select an option

Save Supernats/5c96e1b9409638161a68 to your computer and use it in GitHub Desktop.
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