[Nitro] Proposed change to Module#is

Trans transfire at gmail.com
Wed Nov 7 14:11:23 EST 2007


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.



More information about the Nitro-general mailing list