From: Robert Klemme Date: 2007-01-26T17:20:22+09:00 Subject: Re: Adding methods to String, but only in my own Module? On 25.01.2007 22:34, Greg Hurrell wrote: > Is there any way to add methods to the String class, but only within > the scope of a particular module? Example: adding a "fantastic" method > to String: > > class String > def fantastic > self + "fantastic" > end > end > > Now, given the limited usefulness of the "fantastic" method, I'd like > to be able to confine its impact to my Module only: > > # outside of my module this should raise a NoMethodError > "foo".fantastic > > class Example > def example > "foo".fantastic # should work > end > end > > I suspect the answer is going to be no, but wanted to ask anyway... See the other replies for suggested solutions etc. For me it always seemed easier to use /functions/ for this: def fantastic(s) s + "fantastic" end And you can scope them as you like / need. Kind regards robert