Greg Hurrell
1/25/2007 9:34:00 PM
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...
Cheers,
Greg