On Thu, Aug 16, 2012 at 2:16 PM, Ronnie Aa <[email protected]> wrote:
> I have this:
>
> class Fixnum
>    def times_print(str)
>       times { puts str }
>    end
> end
>
> module Bb
>   def self.test
>     10.times_print('foo')
>   end
> test
> end
>
> It works..
>
> But if some other .rb uses the same name for its Fixnum class extension,
> including different methods, there will be collision ??

Yes.  And with that you have exactly nailed one of the major reasons
why your change is not a good idea. :-)  There are actually more
reasons, e.g. that a number has no job in containing printing methods.

> So I tried to wrap my class extension in a module like this:
>
>
> module Aa
>   class Fixnum
>     def times_print(str)
>       times { puts str }
>     end
>   end
> end

Here you create a new class ::Aa::Fixnum which is totally unrelated to
::Fixnum...

> module Bb
> include Aa
>   def self.test
>
>     10.times_print('foo')
>   end
> test
> end
>
> The class-extention in module Bb does not work, how do I solve this>??

... which you now discovered. :-)

Just do

10.times { print 'foo' }

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to