Class: HelperModule

Inherits:
Module show all
Defined in:
lib/reactive-core/helper_module.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(names, code) ⇒ HelperModule

Returns a new instance of HelperModule.



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/reactive-core/helper_module.rb', line 2

def initialize(names, code)
  self.class.send(:define_method, :helpers) do
    # reverse because this array will be passed to #extend which put precedence in the first passed module
    helpers = names.collect {|name| const_get(name.split('.').first.classify) }.reverse
    #constants doesn't preserve the order in which they are declared! #helpers = constants.collect{|name| const_get(name)}.select{|const| const.is_a? Module}
    # We provide ourself (which is an empty module) if no nested modules are defined because calling #extend with no argument isn't legal.
    helpers.empty? ? self : helpers
  end
  @name = names.join('_')
  class_eval(code)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/reactive-core/helper_module.rb', line 13

def name
  @name
end