Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Speak like Yoda
# port of
# Please refactor this if necessary
# leonb -at- beriedata -dot- nl
class String
def yoda
word = %w{is be will show do try are teach have}.select { |word| self =~ /\b#{word}\b/ }[0]
if word
x = (self =~ /\b#{word}\b/) + word.size
"#{self[x+1,self.size].capitalize}, #{self[0,x].downcase}"
else return self end
puts 'I will teach you'.yoda
puts 'The truth is out there'.yoda
puts 'That is an Imperial shuttle'.yoda
puts 'My husband is giant dork'.yoda
puts 'These fish are tasty'.yoda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.