Calling methods with & operator in Ruby
Today I learned this
2.6.3 :001 > a = [1, 2, 3]
=> [1, 2, 3]
2.6.3 :002 > a.count
=> 3
2.6.3 :003 > a = nil
=> nil
2.6.3 :004 > a.count
Traceback (most recent call last):
4: from /Users/karthikeyan/.rvm/rubies/ruby-2.6.3/bin/irb:23:in `<main>'
3: from /Users/karthikeyan/.rvm/rubies/ruby-2.6.3/bin/irb:23:in `load'
2: from /Users/karthikeyan/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
1: from (irb):4
NoMethodError (undefined method `count' for nil:NilClass)
2.6.3 :005 > a&.count
=> nil