Forum: Nitro Proposed change to Module#is

Posted by Trans (Guest)
on 2007-11-07 20:12
(Received via mailing list)
Here's the change to #is I've been contemplating. I'm thinking it
might make a good override of include actually.


  class Module

    def is(*mods)
      mods.each do |mod|
        if mod.const_defined?(:Self)
          extend mod.const_get(:Self)
        end
      end
      include(*mods)
    end

  end


example:


  module Dog

    def bark; "ruff"; end

    module Self
      def fleas; '. ' * rand(10).to_i; end
    end

  end

  class Spot
    is Dog
  end

  Spot.fleas  #=> '. . . . . '

T.
This topic is locked and can not be replied to.