Module: SleepingKingStudios::Tools::Toolbox::HeritableData

Defined in:
lib/sleeping_king_studios/tools/toolbox/heritable_data.rb

Overview

Mixin to allow defining subclasses of Data classes.

Defined Under Namespace

Modules: ClassMethods Classes: HeritableMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define(*symbols, parent_class: nil) { ... } ⇒ Object

Defines a new heritable Data class.

Parameters:

  • symbols (Array<Symbol>)

    Data members to define.

  • parent_class (Class) (defaults to: nil)

    the parent class to inherit members and methods from.

Yields:

  • additional methods to define on the new Data class.



154
155
156
157
158
159
160
# File 'lib/sleeping_king_studios/tools/toolbox/heritable_data.rb', line 154

def define(*symbols, parent_class: nil, &)
  Data.define(*parent_class&.members, *symbols).tap do |data_class|
    data_class.include(HeritableData)

    define_mixin_for(data_class, parent_class, &)
  end
end

Instance Method Details

#is_a?(type) ⇒ true Also known as: kind_of?

Checks if the object class inherits from type.

Parameters:

  • type (Module)

    the type to check.

Returns:

  • (true)

    if the object class inherits from type, or if the object class inherits members and methods from the given type.



186
187
188
# File 'lib/sleeping_king_studios/tools/toolbox/heritable_data.rb', line 186

def is_a?(type)
  super || self.class < type || false
end