Class: Module
Instance Method Summary collapse
- #module_attribute(*attribute_names, &block) ⇒ Object
- #recursively_define_namespaced_class(class_name, class_to_inherit_from = Object) ⇒ Object
Instance Method Details
#module_attribute(*attribute_names, &block) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/trax/core/ext/module.rb', line 2 def module_attribute(*attribute_names, &block) attribute_names.each do |_attribute_name| singleton_class.__send__("attr_accessor", _attribute_name) instance_variable_set("@#{_attribute_name}", block.call) if block_given? end end |
#recursively_define_namespaced_class(class_name, class_to_inherit_from = Object) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/trax/core/ext/module.rb', line 9 def recursively_define_namespaced_class(class_name, class_to_inherit_from = Object) paths = class_name.split("::") const_name = paths.shift if paths.length > 0 self.const_set(const_name, ::Module.new) unless self.constants.include?(:"#{const_name}") "#{self.name}::#{const_name}".safe_constantize.recursively_define_namespaced_class(paths.join("::"), class_to_inherit_from) else self.const_set(const_name, ::Class.new(class_to_inherit_from)) unless self.constants.include?(:"#{const_name}") end end |