"George Moschovitis" <gm / navel.gr> schrieb im Newsbeitrag
news:797f8269.0401240857.21c64834 / posting.google.com...
> > What do you mean by "flexible way to declare namespaces"?
>
> instead of
>
> module My; module Little; module Namespace
>   class MyClass
>   end
> end; end; end;
>
> something like:
>
> namespace My::Little::Namespace
>   class MyClass
>   end
> end

Well, you can at least do this:

$ irb --prompt simple
>> module Kernel
>>   def namespace(nested, bind = binding, &block)
>>     pre = ""
>>     post = ""
>>
?>     nested.split('::').each do |sym|
?>       raise NameError, "Symbol must start uppercase" unless /^[A-Z]/ =~
sym
>>       pre << "module " << sym << ";"
>>       post << "end;"
>>     end
>>
?>     eval( pre + post, bind )
>>     eval( nested, bind )
>>   end
>> end
=> nil
>> namespace 'Foo::Bar'
=> Kernel::Foo::Bar
>> namespace 'Bar::Foo', binding
=> Bar::Foo
>>

> excuse me for the improper use of 'flexible' :(

:-))

Regards

    robert