--90e6ba61374ec47ce604a41ebf3d
Content-Type: text/plain; charset=UTF-8

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  2  "
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"

--90e6ba61374ec47ce604a41ebf3d--