From: Matthew Kerwin Date: 2013-04-08T21:41:10+09:00 Subject: [ruby-core:54098] Re: [ruby-trunk - Feature #8237][Open] Logical method chaining via inferred receiver --e0cb4efe2dac32024f04d9d8c0f1 Content-Type: text/plain; charset=ISO-8859-1 On Apr 8, 2013 3:10 PM, "wardrop (Tom Wardrop)" wrote: > > This is a feature suggestion that was raised while discussing issue #8191. The feature suggestion is to introduce some form of logical method chaining to address this reasonably common pattern: > > user && user.profile && user.profile.website && user.profile.website.thumbnail > > It would be reasonably trivial to shorten this to: > > user && .profile && .website && .thumbnail > > The implementation I propose would be for Ruby to allow an inferred receiver; the dot prefix would be the syntax for this. The inferred receiver would resolve to the result of the last expression in the current scope. What would be the result of: "abc" foo = lambda { .upcase } "def" foo.call Is it "ABC" ? --e0cb4efe2dac32024f04d9d8c0f1 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Apr 8, 2013 3:10 PM, "wardrop (Tom Wardrop)" <tom@tomwardrop.com> wrote:
>
> This is a feature suggestion that was raised while discussing issue #8= 191. The feature suggestion is to introduce some form of logical method cha= ining to address this reasonably common pattern:
>
> =A0 =A0 user && user.profile && user.profile.website &= amp;& user.profile.website.thumbnail
>
> It would be reasonably trivial to shorten this to:
>
> =A0 =A0 user && .profile && .website && .thumb= nail
>
> The implementation I propose would be for Ruby to allow an inferred re= ceiver; the dot prefix would be the syntax for this. The inferred receiver = would resolve to the result of the last expression in the current scope.

What would be the result of:

=A0=A0=A0 "abc"
=A0=A0=A0 foo =3D lambda { .upcase }
=A0=A0=A0 "def"
=A0=A0=A0 foo.call

Is it "ABC" ?

--e0cb4efe2dac32024f04d9d8c0f1--