-
-
Save nbrew/518159 to your computer and use it in GitHub Desktop.
YodaSpeak translator in ruby with added pivot words
This file contains 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
# 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