ruby - safe navigation operator apple&.color
访问量: 548
refer to:
https://stackoverflow.com/questions/36812647/what-does-ampersand-dot-mean-in-ruby
class Apple attr_accessor :color end apple = Apple.new color: 'red' apple&.color # => red b = nil b&.color #=> nil
所以, &. 就相当于 rails 中的try