Reference (compares sub vs gsub):
http://www.dotnetperls.com/sub-ruby
Answer
cleand_value = "6 red cables, 4 white cables, 9 blue cables".gsub("cables", '')
Output "6 red , 4 white , 9 blue "
Explanation:
value = "abc abc"
# Gsub replaces all instances.
value = value.gsub("abc", "---")
puts value
Output
--- ---
You then can get rid of all the white spaces after the commas the same way.
cleaner_value = cleaned_value.gsub(", ", ",") #replaces all instances
output "6 red, 4 white, 9 blue"
Or use the other solutions and do
cleand_value = "6 red cables, 4 white cables, 9 blue cables".gsub(" cables", '') #notice the space before cables. May cause problems unless you know exactly the input
def my_fun(s, x); s.gsub(x, ''); end