[Nitro] Ruby question...

transfire at gmail.com transfire at gmail.com
Sun Mar 4 09:21:22 EST 2007



On Mar 4, 5:05 am, "George Moschovitis" <george.moschovi... at gmail.com>
wrote:
> Dear devs,
>
> lets say I have the variable:
>
> base = Namespace::MyModule
>
> I need a method (lets call it extract) that works like this:
>
> extract(base) # => Namespace
>
> any ideas?

irb(main):005:0> require 'facets/core/module/dirname'
=> true
irb(main):006:0> module X
irb(main):007:1>   module Y
irb(main):008:2>   end
irb(main):009:1> end
=> nil
irb(main):010:0> X::Y.basename
NoMethodError: undefined method `basename' for X::Y:Module
        from (irb):10
        from :0
irb(main):011:0> X::Y.dirname
=> "X"

I know, the name 'dirname' is kind of odd, but I took the idea from
File along with module/basename btw.

Also

  X::Y.name.split('::')

I'd make that a method of Module too if I could think of a good name
for it.

T.



More information about the Nitro-general mailing list