0
所以我是一个java程序员,我试图在ruby上变得更好,但是我在基本原理上失败并且没有获得任何地方。这里是我的类找不到ruby函数的定义
class Main
a = Car.new
a.instance_variable_set("@make", 'Hyundai')
if a.make == 'Hyundai'
self.get_hyundai_vehicle_information(a)
end
def get_hyundai_vehicle_information(a)
go_to_hyundai_usa_and_select_vehicle
end
end
但我不断收到错误
undefined method 'get_hyundai_vehicle_information' for Main:Class
您需要提供完整的代码才能重现问题。这段代码是不够的 –
你正在类声明中运行它,并且该方法还没有被定义。当你在*类声明期间做事时,订单很重要。 –
只需在声明完成后调用'get_hyundai_vehicle_information'即可。并将其定义为'def self.get_hyundai_vehicle_information' –