[Nitro] A better #is ?

Trans transfire at gmail.com
Fri Jul 27 10:27:41 EDT 2007


Maybe I hit one something... a slight variation on #is.

  class Module

    # Default append function is #include.
    def is(*modules)
      module.each do { |m|
        if m.respond_to?(:append_feature_function)
          send(m.append_feature_function,m)
        else
          include m
        end
      end
    end

  end

Example:

  module Foo
    def self.append_feature_function
      :extend
    end

    def x; "x"; end
  end

  class Bar
    is Foo
  end

  Bar.x  #=> "x"

Thoughts?

T.



More information about the Nitro-general mailing list