You only need to detect structuraly similar code. You absolutely do not need AI for that. You need ASTs.

In Ruby we have the Flay gem, for example.

https://github.com/seattlerb/flay