On Wed, May 25, 2011 at 8:22 PM, jason solomon <solomon.jas / gmail.com>wrote:

> 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?
>

String#replace

s1 = s2 = ""
s2.replace("foo")
s2 #=> "foo"
s1.object_id == s2.object_id

def String
  def fooify
    replace("foo")
  end
end

s = "bar"
s.fooify
s == "foo"