From: Joseph Jones Date: 2015-12-17T21:06:42-07:00 Subject: [ruby-core:72280] [Ruby trunk - Feature #10930] Allow splat operator to work for string interpolation --56738652_725a06fb_16c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Joseph Jones liked your message with Boxer. On December 4, 2015 at 21:53:= 25 MST, 6ftdan=40gmail.com wrote:Issue =2310930 has been updated by Danie= l P. Clark.=7E=7E=7Erubyclass Example def method=5Fmissing m, *a puts =22= Method =23=7Bm=7D called with arguments =22, *a endendExample.new.foo :ba= r, :baz=23Method foo called with arguments =23bar=23bazclass Example def = method=5Fmissing m, *a puts =22Method =23=7Bm=7D called with arguments =23= =7Ba=7D=22 endendExample.new.foo :bar, :baz=23Method foo called with argu= ments =5B:bar, :baz=5D=7E=7E=7ENeither of these are the desired behavior.= It ends up needing to be implemented like this.=7E=7E=7Erubyclass Exampl= e def method=5Fmissing m, *a puts =22Method =23=7Bm=7D called with argume= nts =23=7Ba.to=5Fs=5B1..-2=5D=7D=22 endendExample.new.foo :bar, :baz=23Me= thod foo called with arguments :bar, :baz=7E=7E=7E-----------------------= -----------------=46eature =2310930: Allow splat operator to work for str= ing interpolationhttps://bugs.ruby-lang.org/issues/10930=23change-55245* = Author: Daniel P. Clark* Status: =46eedback* Priority: Normal* Assignee: = ----------------------------------------Currently when you use the splat = operator in a method it pulls the items out of the array for method param= eters.=7E=7E=7Erubydef foo(a,b,c) puts =22=23=7Ba=7D, =23=7Bb=7D, =23=7Bc= =7D=22endbar =3D =5B1,2,3=5Dfoo(*bar)=23 =3D> =221, 2, 3=22=7E=7E=7ESo I = would expect to be able to do =22=23=7B*bar=7D=22 and get either =221, 2,= 3=22 or =221,2,3=22. But when attempting this I get.=7E=7E=7Erubybaz =3D= =5B1,2,3=5D=22=23=7B*baz=7D=22=23 SyntaxError: (irb):53: syntax error, u= nexpected tSTRING=5FDEND, expecting '=3D'=23 =22=23=7B*baz=7D=22=23 =5E=23= (irb):53: unterminated string meets end of file=22=23=7B*=5B1,2,3=5D=7D=22= =23 SyntaxError: (irb):54: syntax error, unexpected tSTRING=5FDEND, expec= ting :: or '=5B' or '.'=23 =22=23=7B*=5B1,2,3=5D=7D=22=23 =5E=23 (irb):54= : unterminated string meets end of file=7E=7E=7EThis doesn't work on any = of the Ruby versions available 1.8 through 2.2.1. They each produce the s= ame error.I propose allowing the splat operator within string interpolati= on to work the same as =5B1,2,3=5D.join(',')=7E=7E=7Erubyfiz =3D =5B1,2,3= =5D=22=23=7B*fiz=7D=22=23 =3D> =221,2,3=22=22=23=7B*=5B1,2,3=5D=7D=22=23 = =3D> =221,2,3=22=7E=7E=7E-- https://bugs.ruby-lang.org/ --56738652_725a06fb_16c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Joseph Jones liked your message with Boxer.


= On December 4, 2015 at 21:53:25 MST, 6ftdan=40gmail.com wrote:
Issue =2310930 has been updated = by Daniel P. Clark.


=7E=7E=7Eruby
class Example
def method=5Fmissing m, *a
puts =22Method =23=7Bm=7D called = with arguments =22, *a
end
end

Example.new.foo :ba= r, :baz
=23Method foo called with arguments
=23bar
=23baz=

class Example
def method=5Fmissing m, *a
puts= =22Method =23=7Bm=7D called with arguments =23=7Ba=7D=22
end
end

Example.new.foo :bar, :baz
=23Method foo called with= arguments =5B:bar, :baz=5D
=7E=7E=7E

Neither of these ar= e the desired behavior. It ends up needing to be implemented like this.<= br />
=7E=7E=7Eruby
class Example
def method=5Fmissing m= , *a
puts =22Method =23=7Bm=7D called with arguments =23=7Ba.to=5F= s=5B1..-2=5D=7D=22
end
end

Example.new.foo :bar, := baz
=23Method foo called with arguments :bar, :baz
=7E=7E=7E
----------------------------------------
=46eature =2310930= : Allow splat operator to work for string interpolation
https://bugs= .ruby-lang.org/issues/10930=23change-55245

* Author: Daniel P.= Clark
* Status: =46eedback
* Priority: Normal
* Assignee:=
----------------------------------------
Currently when you u= se the splat operator in a method it pulls the items out of the array for= method parameters.

=7E=7E=7Eruby
def foo(a,b,c)
p= uts =22=23=7Ba=7D, =23=7Bb=7D, =23=7Bc=7D=22
end

bar =3D = =5B1,2,3=5D
foo(*bar)
=23 =3D> =221, 2, 3=22
=7E=7E=7E

So I would expect to be able to do =22=23=7B*bar=7D=22 and get ei= ther =221, 2, 3=22 or =221,2,3=22. But when attempting this I get.
=
=7E=7E=7Eruby
baz =3D =5B1,2,3=5D

=22=23=7B*baz=7D=22=

=23 SyntaxError: (irb):53: syntax error, unexpected tSTRING=5F= DEND, expecting '=3D'
=23 =22=23=7B*baz=7D=22
=23 =5E=23 (irb):53: unterminated string meets end of file

=22=23= =7B*=5B1,2,3=5D=7D=22

=23 SyntaxError: (irb):54: syntax error,= unexpected tSTRING=5FDEND, expecting :: or '=5B' or '.'
=23 =22=23=7B= *=5B1,2,3=5D=7D=22
=23 =5E
=23 (irb):54: unterminat= ed string meets end of file
=7E=7E=7E

This doesn't work o= n any of the Ruby versions available 1.8 through 2.2.1. They each produc= e the same error.

I propose allowing the splat operator within= string interpolation to work the same as =5B1,2,3=5D.join(',')

=7E=7E=7Eruby
fiz =3D =5B1,2,3=5D

=22=23=7B*fiz=7D=22=23 =3D> =221,2,3=22

=22=23=7B*=5B1,2,3=5D=7D=22
=23 = =3D> =221,2,3=22
=7E=7E=7E



--
https://b= ugs.ruby-lang.org/
--56738652_725a06fb_16c--