Skip to content

Commit

Permalink
Define search loop in includeModuleAt
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Aug 22, 2024
1 parent 2fbda4c commit 6af36f2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions class.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,30 @@ func (mrb *State) prepareSingletonClass(obj RObject) error {
return nil
}

func (mrb *State) includeModuleAt(class, insPos, module RClass, superSearch int) int {
func (mrb *State) includeModuleAt(class, insPos, module RClass, searchSuper bool) int {
for module != nil {
parentClass := class.Super()

if module.Flags()&FlagClassIsPrepended != 0 {
goto Skip
}

for parentClass != nil {
if !searchSuper {
break
}

parentClass = parentClass.Super()
}
Skip:
module = module.Super()
}

return 0
}

func (mrb *State) IncludeModule(class, module RClass) error {
mrb.includeModuleAt(class, findOrigin(class), module, 1)
mrb.includeModuleAt(class, findOrigin(class), module, true)

return nil
}
Expand Down

0 comments on commit 6af36f2

Please sign in to comment.