Skip to content

Instantly share code, notes, and snippets.

@nbrew
Forked from LeipeLeon/YodaSpeak.rb
Created August 10, 2010 22:53
Show Gist options
  • Save nbrew/518159 to your computer and use it in GitHub Desktop.
Save nbrew/518159 to your computer and use it in GitHub Desktop.
YodaSpeak translator in ruby with added pivot words
# 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 look help see can learn has}.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