Perhaps since you are getting the string from a text file, there is a \n
at the end of the string. Hence, the last 4
is actually 4\n
.
Try this to see if it works:
def remove_dup(str)
str.chomp.split(",").uniq.join(",")
end
The chomp
method will remove the carriage return characters from the end of the string.