f



String Interpolation of Compound Statement

Hi folks.  I come from a language where we don=E2=80=99t have string interp=
olation.  Here=E2=80=99s what I would usually write:

@f +=3D "\t<label for=3D\"" + @h[("s_fieldname_" + i.to_s)].to_s + "\">" + =
@fieldname.capitalize + =E2=80=9C:"

Now I=E2=80=99ve been told there are less errors with string interpolation.=
  How can I translate that?  I get hung up on the internal bit here:

@h[("s_fieldname_" + i.to_s)

I=E2=80=99m sure it=E2=80=99s out there.  I appreciate any input.

Cheers
0
BeeRich33
9/1/2016 9:14:14 PM
comp.lang.ruby 48885 articles. 0 followers. Post Follow

1 Replies
552 Views

Similar Articles

[PageSpeed] 6

On 9/1/2016, BeeRich33 wrote:

> @f += "\t<label for=\"" + @h[("s_fieldname_" + i.to_s)].to_s +
>   "\">" + @fieldname.capitalize + ":"
> 
> Now I've been told there are less
> errors with string interpolation.  How
> can I translate that?

@fieldname = "foo"
i = 2
@h = {"s_fieldname_2" => 1984}

"\t<label for=\"" + @h[("s_fieldname_" + i.to_s)].to_s +
  "\">" + @fieldname.capitalize + ":"
    ==>"\t<label for=\"1984\">Foo:"

"\t<label for=\"#{@h[("s_fieldname_" + i.to_s)]}\">#{@fieldname.capitalize}:"
    ==>"\t<label for=\"1984\">Foo:"

0
Robert
11/24/2016 10:08:52 PM
Reply: