On Thu, Oct 7, 2010 at 7:33 AM, John Mair <jrmair / gmail.com> wrote:
> When classes are inherited in Ruby the singleton classes are also
> inherited:
>
> class A
> =A0def self.hello
> =A0 =A0puts "hello"
> =A0end
> end
>
> class B < A
> end
>
> B.hello #=3D> "hello"

ok. single inheritance

> Yet with modules, this is not the case:
>
> module M
> =A0def self.goodbye
> =A0 =A0puts "goodbye"
> =A0end
> end
>
> class A
> =A0include M
> end
>
> A.goodbye #=3D> NameError


class A
  include M
  include N
end

now, which goodbye??

> To get around this limitation many ppl resort to this ugly hack:

sorry, ' prefer specs over hacks :-)

module ClassMethods
  def goodbye
    puts "goodbye"
  end
end
#=3D> nil

class A
  class << self
    include ClassMethods
  end
end
#=3D> #<Class:A>

A.goodbye
goodbye

clearer, if i may say.

best regards -botp