Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.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_Function_Methods - Fatal编程技术网

Ruby 为什么我会得到一个命名者?

Ruby 为什么我会得到一个命名者?,ruby,function,methods,Ruby,Function,Methods,当我试着用say运行它时 class UnitCircle def prompt puts "Enter a number: " @number = gets @number = @number.to_i puts "Enter a trigonometric equation to perform on that number: " @eqn = gets end end uc = UnitCirc

当我试着用say运行它时

class UnitCircle
    def prompt
        puts "Enter a number: "
        @number = gets
        @number = @number.to_i
        puts "Enter a trigonometric equation to perform on that number: "
        @eqn = gets
    end
end
uc = UnitCircle.new
uc.prompt
num = Math.send(uc.instance_eval {@eqn}, uc.instance_eval {@number})
我得到一个无方法错误,为什么

@number = 30
@eqn = sin
获取
方法将包括新行符号“\n”。所以你必须
chomp
it。 如果不选择chomp,则最终将调用方法“sin\n”而不是“sin”

class UnitCircle
    def prompt
        puts "Enter a number: "
        @number = gets.chomp
        @number = @number.to_i
        puts "Enter a trigonometric equation to perform on that number: "
        @eqn = gets.chomp
    end
end