Class: Module

Inherits:
Object show all
Defined in:
lib/plexus/ext.rb

Instance Method Summary collapse

Instance Method Details

#extends_host(*params) ⇒ Object

Helper which purpose is, given a class including a module, to make each methods defined within a module’s submodule ‘ClassMethods` available as class methods to the receiving class.

Example:

module A
  extends_host
  module ClassMethods
    def selfy; puts "class method for #{self}"; end
  end
end

class B; include A; end

B.selfy
# => class method for B

Parameters:

  • *params (Hash)

    a customizable set of options



69
70
71
72
73
74
75
76
77
78
# File 'lib/plexus/ext.rb', line 69

def extends_host(*params)
  args = (params.pop if params.last.is_a? Hash) || {}
  @_extension_module = args[:with] || :ClassMethods

  def included(base)
    unless @_extension_module.nil?
      base.extend(self.const_get(@_extension_module))
    end
  end
end

#included(base) ⇒ Object



73
74
75
76
77
# File 'lib/plexus/ext.rb', line 73

def included(base)
  unless @_extension_module.nil?
    base.extend(self.const_get(@_extension_module))
  end
end