ruby pig_latin.rb
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby pig_latin.rb相关的知识,希望对你有一定的参考价值。
def pig_latin(input)
ind = input.index(/[aeiouAEIOU]/)
if(ind != 0)
if(ind != nil)
first_chunk = input[ind, input.length]
sec_chunk = input[/[^aeiouAEIOU]+/]
return first_chunk + sec_chunk + "ay"
else
return input + "ay"
end
else
return input
end
end
def pig_latin_sentence(sentence)
input = sentence
pig_sentence = ""
count = 0
input.split(' ').each do |word|
pigWord = pig_latin(word)
if(pigWord != word)
count += 1
end
print "#{pigWord} "
end
puts
puts "Count : #{count}"
end
#puts pig_latin("testing")
pig_latin_sentence("The pig is from latin")
# Implement ARGV constant with pig_latin
puts "Pig latin a sentence: "
pig_latin_sentence(ARGV.join(' '))
以上是关于ruby pig_latin.rb的主要内容,如果未能解决你的问题,请参考以下文章
Ruby运算符
Ruby 25 岁了!Ruby 之父说 Ruby 3 有望 3 倍提速
如何学习ruby?Ruby学习技巧分享
ruby Ruby脚本,看看是否用openssl编译了ruby
什么是ruby?
ruby和ruby ee