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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -