Stefano Crocco
8/6/2007 8:05:00 PM
Alle lunedì 6 agosto 2007, Gabriel Dragffy ha scritto:
> Hi all
>
> I have a module file which contains 'class String' and a couple of
> custom methods for me to add to Object::String. So I do something like:
> require 'mystring' or load or whatever. It doesn't extend String's
> functionallity... no doubt because the modules contents are isolated
> in their own namespace... How to get around that?
>
>
> Many thanks
>
>
>
>
> Gabriel Dragffy
>
> gabe@dragffy.com
Do you mean the following situation?
# file mystring.rb
module MyMod
class String
...
end
end
In this case, you're right. This piece of (pseudo) code creates the class
MyMod::String, which is a completely different thing from the String class.
If you want to extend String, you simply have to move the class
String;...;end part outside the definition of module MyMod:
# file mystring.rb
class String
...
end
module MyMod
...
end
I hope this help
Stefano