您好我有以下简单的代码
#! /usr/bin/ruby
input = gets.downcase.chomp.to_sym
send input
def abc
puts "Hi"
end
当我运行脚本并输入abc时,我得到了
test.rb:5:in `<main>': undefined method `abc' for main:Object (NoMethodError)
使用ruby 1.9.1
答案 0 :(得分:1)
请试试这个:
#! /usr/bin/ruby
def abc
puts "Hi"
end
input = gets.downcase.chomp.to_sym
send input
希望代码有意义。