Hendrik Kleine Hendrik Kleine - 5 months ago 23
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 ()

Thanks

Answer
> puts "Some words #{input[2].to_s.gsub('[','(').gsub(']', ')')} some more words"
#=> Some words ("Accounting", "Customer Relations") some more words
Comments