Class: Trax::Core::NamedClass

Inherits:
Object
  • Object
show all
Includes:
SilenceWarnings
Defined in:
lib/trax/core/named_class.rb

Class Method Summary collapse

Class Method Details

.new(_name, _parent_klass = Object, **options, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/trax/core/named_class.rb', line 6

def self.new(_name, _parent_klass=Object, **options, &block)
  klass = silence_warnings {
    ::Object.set_fully_qualified_constant(_name, ::Class.new(_parent_klass) {
      define_singleton_method(:name) { _name }
    })
  }

  options.each_pair do |k,v|
    klass.class_attribute k
    klass.__send__("#{k}=", v)
  end unless options.blank?

  klass.class_eval(&block) if block_given?

  klass
end