From: Joseph Jones Date: 2015-12-17T21:07:04-07:00 Subject: [ruby-core:72295] [Ruby trunk - Bug #11816] [Open] Partial safe navigation operator --56738668_354fe9f9_16c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Joseph Jones liked your message with Boxer. On December 14, 2015 at 11:19= :37 MST, ruby-core=40marc-andre.ca wrote:Issue =2311816 has been reported= by Marc-Andre Lafortune.----------------------------------------Bug =231= 1816: Partial safe navigation operatorhttps://bugs.ruby-lang.org/issues/1= 1816* Author: Marc-Andre Lafortune* Status: Open* Priority: Normal* Assig= nee: Yukihiro Matsumoto* ruby -v: preview 2* Backport: 2.0.0: UNKNOWN, 2.= 1: UNKNOWN, 2.2: UNKNOWN----------------------------------------I'm extre= mely surprised (and disappointed) that, currently: x =3D nil x&.foo.bar =23= =3D> NoMethodError: undefined method =60bar' for nil:NilClassTo make it = safe, you have to write =60x&.foo&.bar=60. But if =60foo=60 is never supp= osed to return =60nil=60, then that code isn't =22fail early=22 in case i= t actually does. =60nil&.foo.bar=60 is more expressive, simpler and is pe= rfect if you want to an error if =60foo=60 returned =60nil=60. To actuall= y get what you want, you have to resort using the old form =60x && x.foo.= bar=60...In CoffeeScript, you can write =60x()=3F.foo.bar=60 and it will = work well, since it gets compiled to if ((=5Fref =3D x()) =21=3D null) =7B= =5Fref.foo.bar; =7DAll the discussion in =2311537 focuses on =60x&.foo&.= bar=60, so I have to ask:Matz, what is your understanding of =60x&.foo.ba= r=60=3FI feel the current implementation is not useful and should be chan= ged to what I had in mind. I can't see any legitimate use of =60x&.foo.ba= r=60 currently.-- https://bugs.ruby-lang.org/ --56738668_354fe9f9_16c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Joseph Jones liked your message with Boxer.


= On December 14, 2015 at 11:19:37 MST, ruby-core=40marc-andre.ca wrote:
Issue =2311816 has been = reported by Marc-Andre Lafortune.

----------------------------= ------------
Bug =2311816: Partial safe navigation operator
htt= ps://bugs.ruby-lang.org/issues/11816

* Author: Marc-Andre Lafo= rtune
* Status: Open
* Priority: Normal
* Assignee: Yukihi= ro Matsumoto
* ruby -v: preview 2
* Backport: 2.0.0: UNKNOWN, 2= .1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------I'm extremely surprised (and disappointed) that, currently:

x =3D nil
x&.foo.bar =23 =3D> NoMethodError: undefined met= hod =60bar' for nil:NilClass

To make it safe, you have to writ= e =60x&.foo&.bar=60. But if =60foo=60 is never supposed to return =60nil=60= , then that code isn't =22fail early=22 in case it actually does. =60nil&= .foo.bar=60 is more expressive, simpler and is perfect if you want to an = error if =60foo=60 returned =60nil=60. To actually get what you want, you= have to resort using the old form =60x && x.foo.bar=60...

In = CoffeeScript, you can write =60x()=3F.foo.bar=60 and it will work well, s= ince it gets compiled to

if ((=5Fref =3D x()) =21=3D null)= =7B
=5Fref.foo.bar;
=7D

All the discussio= n in =2311537 focuses on =60x&.foo&.bar=60, so I have to ask:

= Matz, what is your understanding of =60x&.foo.bar=60=3F

I feel= the current implementation is not useful and should be changed to what I= had in mind. I can't see any legitimate use of =60x&.foo.bar=60 currentl= y.




--
https://bugs.ruby-lang.org/
--56738668_354fe9f9_16c--