From: Robert Klemme Date: 2012-08-16T22:15:26+09:00 Subject: Re: extending class, namespace question On Thu, Aug 16, 2012 at 2:16 PM, Ronnie Aa 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/