Skip to content

Instantly share code, notes, and snippets.

@LeipeLeon
Created February 11, 2009 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LeipeLeon/62350 to your computer and use it in GitHub Desktop.
Save LeipeLeon/62350 to your computer and use it in GitHub Desktop.
Speak like Yoda
# port of http://www.perlmonks.org/?node_id=162190
#
# 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
end
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