新手问题 请问 ruby 中 gets.chomp () 和 ARGV 怎么结合使用

a14100360 · September 27, 2012 · Last by qiqi replied at July 30, 2013 · 6256 hits

请问 ruby 中 gets.chomp() 和 ARGV 怎么结合使用,一直想不通我先 vi ex1.rb first,second,third = ARGV puts“The script is called: #{$0}” puts "he is #{first} years old." puts "he is #{second} tall." puts "he is #{third} heavy." 最后执行 ruby ex1.rb 22 180 65 在这个里面怎么加入 gets.chomp() 用法? 雪地里跪求!!!!!!!!!!!!!!!

虽然我很想帮你,可是我是在看不懂你在说什么。

vi 按 i 进入插入模式 你可以在第一行,或者第二行,或者第三行,或者第四行,或者第五行插入 gets.chomp()

我按照你说的下了,还是错误啊,提示找不到 gets.

提示的是找不到 gets 这个文件或目录,

#2 楼 @luikore 大哥,还是不行啊

問題是你要實現什么啊?這個可以輸入 例如 myvar = gets.chomp() puts myvar

用 STDIN.gets.chomp() 就不会报错了。再看 lrthw 吧,加油。@a14100360

在 gets 前面加$stdin 就 ok 了 $stdin.gets.chomp()

You need to Sign in before reply, if you don't have an account, please Sign up first.