ruby - How to remove a trailing comma? -
given strings like:
bob bob, bob bob burns,
how can return w/o comma?
bob bob bob bob burns
also, want method not break if passed nil, return nil?
def remove_trailing_comma(str) !str.nil? ? str.replace(",") :nil end
my thought use string.chomp:
returns new string given record separator removed end of str (if present).
does want?
def remove_trailing_comma(str) str.nil? ? nil : str.chomp(",") end
Comments
Post a Comment