我在使用insured?
检查值是否为真时遇到未定义的方法错误:
代码:
car_rental = 100
insured = true
extra_insurance_fee = 10
damages = 30
renter_payment = car_rental + (insured? ? extra_insurance_fee : damages)
puts renter_payment
控制台输出:
/Users/###/Desktop/test.rb:6:in `<main>': undefined method `insured?' for main:Object (NoMethodError)
[Finished in 0.1s with exit code 1]
[shell_cmd: ruby "/Users/###/Desktop/test.rb"]
[dir: /Users/###/Desktop]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
知道如何解决这个问题吗?