Hendrik Kleine Hendrik Kleine - 1 year ago 69
Ruby Question

Ruby use gsub within string interpolation

I'm trying to use gsub within a string interpolation

puts "Some words #{Lookup1[input[2]].gsub("[", "(")} some more words"

The input array looks like this:

input = [0,22,["Accounting","Customer Relations"],nil,nil,nil,nil]

My goal is to replace [] with ()


Answer Source
> puts "Some words #{input[2].to_s.gsub('[','(').gsub(']', ')')} some more words"
#=> Some words ("Accounting", "Customer Relations") some more words
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download