module DeepCover::Node::Mixin::CanAugmentChildren::ClassMethods
Public Instance Methods
has_child(remap: nil, **args)
click to toggle source
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, ...}
Calls superclass method
# 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