ruby 原猪拉丁语翻译

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 原猪拉丁语翻译相关的知识,希望对你有一定的参考价值。

vowels = ['a', 'e', 'i', 'o', 'u']
consonants = ('a'..'z').to_a - vowels

puts "Please enter your name." 
  name = gets.chomp.downcase

firstLetter = name[0,1]
secondLetter = name[1,1]
without_firstletter = name[1..-1]
without_secondletter = name[2..-1]

	if vowels.include?(name[0,1]) 
		puts "Your name in Piglatin is " + name.capitalize + "ray. Carry on."
	elsif consonants.include?(name[0,1]) && consonants.include?(name[1,1]) 
		puts "Your name in Piglatin is " + without_secondletter.capitalize + firstLetter + secondLetter + "ay. Congratulations."
	else consonants.include?(name[0,1]) 	
		puts "Your name in Piglatin is " + without_firstletter.capitalize + firstLetter + "ay. Congratulations."
	end
	
# jennie louie's 
def piglatin
puts "your word?"
word = gets.chomp
split_word = word.split('');  #split word into array of letters
vowels = ["a", "e", "i", "o", "u"]
loop=true
    while loop
    first_letter = split_word[0]
          if vowels.include?(first_letter)
            loop=false
          else # if not a vowel
            letter_to_move = split_word.shift
            split_word.push(letter_to_move)
            loop=true
          end #if
    end #while
new_word = split_word.push("ay").join
puts "The word " + word + " in pig latin is " + new_word
end
piglatin()

以上是关于ruby 原猪拉丁语翻译的主要内容,如果未能解决你的问题,请参考以下文章

text JavaScript中的猪拉丁语翻译

如何创建用于猪拉丁语和 izzle 翻译的代码以及同时应用它们的代码?

阿拉丁- Sax Ruby

红宝石ruby

Python3 创建基本功能 - 删除特定字符串/翻译

SQL WHERE 子句与拉丁文和泰文字符的列不匹配