Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]
"shirts"

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

like image 691
Trip Avatar asked Mar 04 '11 16:03

Trip


1 Answers

Simplest:

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

or

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! /$/, '/'
like image 194
Jakub Hampl Avatar answered Sep 22 '22 07:09

Jakub Hampl