--001a113a3e0afc39130522b80d3b
Content-Type: text/plain; charset=UTF-8

On 23/10/2015 2:46 AM, <merch-redmine / jeremyevans.net> 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  truct.new(:x)
> >     o  .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.

--001a113a3e0afc39130522b80d3b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p dir="ltr"><br>
On 23/10/2015 2:46 AM, &lt;merch-redmine / jeremyevans.net&gt; wrote:<br>
&gt;<br>
&gt; Issue #11537 has been updated by Jeremy Evans.<br>
&gt;<br>
&gt;<br>
&gt; Tom Reznick wrote:<br>
&gt; &gt; Hi,<br>
&gt; &gt;<br>
&gt; &gt; I think we may have found some unexpected behavior with the `.?` operator.<br>
&gt; &gt;<br>
&gt; &gt; If I call the following:<br>
&gt; &gt;<br>
&gt; &gt;  s = Struct.new(:x)<br>
&gt; &gt;  o = s.new()<br>
&gt; &gt;  o.x #=&gt; nil<br>
&gt; &gt;  o.x.nil? #=&gt; true<br>
&gt; &gt;  o.x.?nil? #=&gt; nil<br>
&gt; &gt;  o.x.kind_of?(NilClass) #=&gt; true<br>
&gt; &gt;  o.x.?kind_of?(NilClass) #=&gt; nil<br>
&gt; &gt;  o.x.methods.include?(:nil?) #=&gt; true<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; While it&#39;s arguably a bit peculiar to try to check that `nil`s `nil`, in a `nil`-safe way, `.?kind_of?(NilClass)` could reasonably return `true`.<br>
&gt;<br>
&gt; I think it&#39;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&#39;m not sure if `.?` is a good idea syntax-wise, but if you are going to have it, it shouldn&#39;t have special cases for specific methods.<br>
&gt;</p>
<p dir="ltr">I agree, or put another way: if you&#39;re testing for nil in two ways, .? has higher priority. That makes it a programmer issue, not auby one.</p>

--001a113a3e0afc39130522b80d3b--