Module: DeepCover::Node::Mixin::CanAugmentChildren::ClassMethods
- Defined in:
- lib/deep_cover/node/mixin/can_augment_children.rb
Instance Method Summary collapse
-
#has_child(remap: nil, **args) ⇒ Object
This handles the following shortcuts: has_child foo: NodeClass, … same as: has_child foo: [], remap: NodeClass, … same as: has_child foo: [NodeClass, …], remap: NodeClass, ….
Instance Method Details
#has_child(remap: nil, **args) ⇒ Object
This handles the following shortcuts:
has_child foo: {type: NodeClass, ...}
same as:
has_child foo: [], remap: {type: NodeClass, ...}
same as:
has_child foo: [NodeClass, ...], remap: {type: NodeClass, ...}
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/deep_cover/node/mixin/can_augment_children.rb', line 44 def has_child(remap: nil, **args) name, types = args.first if types.is_a? Hash raise 'Use either remap or a hash as type but not both' if remap remap = types args[name] = types = [] end if remap.is_a? Hash type_map = remap remap = ->(child) do klass = type_map[child.type] if child.respond_to? :type klass ||= type_map[child.class] klass end types.concat(type_map.values).uniq! end super(**args, remap: remap) end |