From: Jeremy Date: 2003-03-12T11:12:58+09:00 Subject: How to add a destructive method to the String class... Hi, I just started learning Ruby this weekend, and I have to say that I've fallen in love with it so far. It's a beautiful beautiful language. =0) In messing around with it, I found that I needed a method that capitalizes all the words in a string, assuming that each word is seperated by a space. I did this, and it works fine: class String def capwords self.split.each { |word| word.capitalize! }.join(" ") end end It does what I need, but it got me thinking. How would I make this destructive? In other words, rather than having to do an assingment like this: title = "This is the title" title = title.capwords I'd like to do this instesad: title.capwords! I tried creating a capwords! method, using the line from capwords, and I added a "self =" directive in front of the code of the capwords method, but Ruby tells me "Can't change the value of self". Would anyone have any words of wisdom, or at least a directional pointer, on what to do with this? I'd really appreciate it! Thanks, Jeremy