Bit của trường hợp cạnh, nhưng bất kỳ ý tưởng nào tại sao & & = sẽ hoạt động theo cách này? Tôi đang sử dụng 1.9.2.Trường hợp Ruby && = edge
obj = Object.new
obj.instance_eval {@bar &&= @bar} # => nil, expected
obj.instance_variables # => [], so obj has no @bar instance variable
obj.instance_eval {@bar = @bar && @bar} # ostensibly the same as @bar &&= @bar
obj.instance_variables # => [:@bar] # why would this version initialize @bar?
Để so sánh, || = khởi tạo các instance variable để nil, như tôi mong đợi:
obj = Object.new
obj.instance_eval {@foo ||= @foo}
obj.instance_variables # => [:@foo], where @foo is set to nil
Cảm ơn!
Bài đăng này được tìm thấy dễ thương với [SymbolHound] (http://www.symbolhound.com/)! –