Trip Trip - 1 year ago 90
Ruby Question

How to append a string in Ruby

I am trying to simply add a '/' at the end of this string. What is the best way to do this?

>> params[:id]

I would like to make
params[:id] == "shirts/"
. How do I add a
at the end of that string?

Answer Source


params[:id] = params[:id] + '/'


params[:id] += '/'

Moar fancy:

params[:id] << '/'

Yet another way to do this:

params[:id].concat '/'

If you really really for some bizzare reason insist on gsub:

params[:id].gsub! /$/, '/'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download