Ruby如何解析:a.b = B.new a.b.c = C.new?

时间:2018-03-08 18:37:50

标签: ruby authorize.net

我假设它将其视为

a.b = (B.new (a.b.c = C.new))

这是一行:

request.transactionRequest.payment = PaymentType.new request.transactionRequest.payment.creditCard = CreditCardType.new('4242424242424242','0220','123')

https://developer.authorize.net/hello_world/

我假设它会将其视为

  

request.transactionRequest.payment =(PaymentType.new(request.transactionRequest.payment.creditCard = CreditCardType.new(' 4242424242424242',' 0220',' 123&# 39;)))

如果payment.creditCard已设置,如何分配payment?不会产生零指针错误吗?即使它有效,为什么要在设置payment时覆盖payment.creditCard呢?

1 个答案:

答案 0 :(得分:1)

缺少换行符,就是全部:

request.transactionRequest.payment = PaymentType.new
request.transactionRequest.payment.creditCard = CreditCardType.new('4242424242424242','0220','123')

虽然单行版本是有效的Ruby语法,但如果没有正当理由,它也不是你在生产代码中所做的事情。