I commonly need to trim characters from the end of a string (when building SQL queries, I have trailing commas, brackets, even words sometimes), so I wrote the following:class String  def trim(amount=1)    self[0..-(amount+1)]  end  def trim!(amount=1)    self[0..-1] = trim(amount)  endendThe dangerous method, trim!, calls the safe method, trim. According to the Ruby Style Guide, this is backwards.How do I rewrite this so the safe method calls the dangerous method, without changing the functionality?Sample output:str = Hello World!puts str            #=> Hello World!puts str.trim       #=> Hello Worldputs str.trim 7     #=> Helloputs str            #=> Hello World!puts str.trim!      #=> Hello Worldputs str.trim! 6    #=> Helloputs str            #=> Hello
Writing a safe class method in terms of a dangerous one
ruby