undefined method `[]=' for nil:NilClass
코드 :어떤 점이 직렬 점에서 nil인지 빠르게 결정합니까?
a.b.c.d['test'].e['foo']
내 솔루션 :
puts "got it: #{a.inspect}" if a.nil?
puts "got it: #{a.b.inspect}" if a.b.nil?
puts "got it: #{a.b.c.inspect}" if a.b.c.nil?
옆의 생산 예외를 처리 할 수. 또한 개발 단계에서 객체를 더 빠르게 찾을 수 있습니다.
(https://stackoverflow.com/questions/9159032/is-there-a-nicer-way-to-write-this-type-of-nil-check)