Say we want to write a String method called clear that takes a given
string and modifies that string to be equal to "".

Ex.

str = "string"

we call str.clear and we get back "", not just "" printed to the screen,
but the value of str is now "" (mutate the original string).


I understand that the following code would just print "" to the screen
but not modify the actual str object.

class String
  def clear
    ""
  end
end


How would you write a method that actually modifies the str object?

-- 
Posted via http://www.ruby-forum.com/.