On 23/10/2015 2:46 AM, wrote: > > Issue #11537 has been updated by Jeremy Evans. > > > Tom Reznick wrote: > > Hi, > > > > I think we may have found some unexpected behavior with the `.?` operator. > > > > If I call the following: > > > > s = Struct.new(:x) > > o = s.new() > > o.x #=> nil > > o.x.nil? #=> true > > o.x.?nil? #=> nil > > o.x.kind_of?(NilClass) #=> true > > o.x.?kind_of?(NilClass) #=> nil > > o.x.methods.include?(:nil?) #=> true > > > > > > While it's arguably a bit peculiar to try to check that `nil` is `nil`, in a `nil`-safe way, `.?kind_of?(NilClass)` could reasonably return `true`. > > I think it's completely expected that `nil.?kind_of?(NilClass)` returns `nil` and not `true`. The whole point of `.?` is to return `nil` without calling the method if the receiver is `nil`. I'm not sure if `.?` is a good idea syntax-wise, but if you are going to have it, it shouldn't have special cases for specific methods. > I agree, or put another way: if you're testing for nil in two ways, .? has higher priority. That makes it a programmer issue, not a ruby one.