Skip to content

Instantly share code, notes, and snippets.

@shereefb
Created June 14, 2012 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shereefb/2932630 to your computer and use it in GitHub Desktop.
Save shereefb/2932630 to your computer and use it in GitHub Desktop.
Implementations of pig latin in ruby
# def translate(word)
# vowels = ["a","e","i","o","u"]
# if !vowels.include?(word[0])
# if word[0..1] == "qu"
# word[2..-1]+"quay"
# else
# counter = 0
# while !vowels.include?(word[counter])
# counter += 1
# end
# word[counter..-1] + word[0..(counter-1)] +"ay"
# end
# else
# word+"ay"
# end
# end
def translate(word)
index = (word.start_with?('qu') ? 2 : word =~ /[aeiou]/)
# if word.start_with?('qu')
# index = 2
# else
# index = word =~ /[aeiou]/
# end
index ||= 0
if index == 0
word + 'ay'
else
word[index..-1] + word[0..index-1] + 'ay'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment