Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将这个八球脚本转换为ruby_Ruby - Fatal编程技术网

如何将这个八球脚本转换为ruby

如何将这个八球脚本转换为ruby,ruby,Ruby,然后,当我调用fortune('text')时,它会从数组中获取一个值谷歌“雇用一名自由职业者”,或者,你尝试过什么?最好使用常量。这样,您就可以一次又一次地创建相同的数组。但它仍然有效:) <SCRIPT LANGUAGE="JavaScript"> <!-- Begin var answers = new Array( "Yes.", "No.", "My sources are pointing toward yes.", "It's possible.", "Ver

然后,当我调用
fortune('text')
时,它会从数组中获取一个值

谷歌“雇用一名自由职业者”,或者,你尝试过什么?最好使用常量。这样,您就可以一次又一次地创建相同的数组。但它仍然有效:)
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var answers = new Array(
"Yes.",
"No.", 
"My sources are pointing toward yes.", 
"It's possible.",
"Very unlikely.", 
"Can you repeat the question?",
"Absolutely not.", 
"Sure.",
"Ask again later."
);
function fortune() {
num = Math.round( (answers.length - 1) * Math.random());
return answers[num];
}
//  End -->
</script>
def fortune
  ["Yes.",
   "No.", 
   "My sources are pointing toward yes.", 
   "It's possible.",
   "Very unlikely.", 
   "Can you repeat the question?",
   "Absolutely not.", 
   "Sure.",
   "Ask again later."].sample
end